Single command to generate & copy public SSH key

I always for­get how to run this sim­ple com­mand, so I’ll just leave it here so you can use it and I won’t for­get it.

Reg­u­lar Gen­er­ate & Copy pub­lic SSH keys

$ ssh-keygen; ssh-copy-id user@host; ssh user@host

Just change the user@host and you’re on your way.

Cus­tom Port

If your host has a dif­fer­ent SSH access port, then it get’s a lit­tle trick­ier, but still works:

$ ssh-keygen; ssh-copy-id ‘-p XXXX -i ~/.ssh/id_rsa.pub username@host’; ssh user@host

Note that the ssh-copy-id call is a lit­tle dif­fer­ent, and exe­cute in quotes (if you copy & paste, the single-quotes can cause error, so replace them with nor­mal single-quotes).

Source: Sim­ple, Cus­tom Port

Leave a Reply