An easy way to copy your ssh public key to a remote host using ssh-copy-id on OSX

Here is a good little tip to save you some time uploading your public key to a remote host (tested to work on OSX Lion).

ssh-copy-id copies your key up to a remote host (via ssh with your password) and even assigns the correct permission to home, ~/.ssh, and ~/.ssh/authorized_keys directories for you.

For some reason it doesn’t ship with OSX, but you can just copy it from your remote linux host and it’ll work fine.

First copy ssh-copy-id down from your remote host…

sudo scp [email protected]:/usr/bin/ssh-copy-id /usr/bin

Make sure it has execute permissions with…

sudo chmod +x /usr/bin/ssh-copy-id

Upload your key to the remote host (this will ask your for your password)…

ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]

Now try logging into the machine, with "ssh '[email protected]'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting.

Hopefully, that’s it. Next time you want to copy your public key up to a new host, you’ll just need to do the final step each time.

If you get the error “/usr/bin/ssh-copy-id: ERROR: No identities found” when you try to copy your key up, it’s basically because it can’t find your local public key file that you’ve specified (~/.ssh/id_rsa.pub in the example above). Have a look in your ~/.ssh/ to see if your public key is there and what the file is called (I’ve seen id_dsa.pub before as well).

top