If you read Peter’s tutorial a while back on how to create an SSH key, you probably found it a little annoying that you had to sign in and out of your server multiple times to copy your key over and test it on a remote machine. Stop wasting any more time needlessly typing in your password to upload the key and let ssh-copy-id do it for you.
You might have seen it in last week’s cheat sheet, but I’d like to document it further. Basically, all you need to do is call ssh-copy-id to your server just like you would for ssh:
ssh-copy-id user@remote.server.net
When you run that, you will have to type in your password for the remote server, but only once. ssh-copy-id will automatically copy your key over and change the permissions appropriately. No more needless chmod-ing or scp-ing.
Later on, I’ll go into details of a graphical application that will also do this and more for you.



Skavoovie wrote:
Why bother with another script?
Just do it all via the command-line:
$ cat ~/.ssh/id_dsa.pub | ssh remoteuser@remotehost ‘cat - >> ~/.ssh/authorized_keys; chmod 700 ~/.ssh ; chmod 600 ~/.ssh/*’
This appends your local public key to the remote machine’s authorized_keys file, and at the same time, ensures permissions are set correctly on the remote machine’s .ssh directory and files within that directory.
# Posted on 22-Aug-07 at 4:18 pm
Jacob wrote:
Skavoovie:
It isn’t “just another script.” This is actually a tool that is included with the openssh client. Much easier than your listed commands, it takes care of permissions and such for you.
# Posted on 22-Aug-07 at 4:25 pm
Skavoovie wrote:
Just think it’s better to learn how to master the functionality of ssh rather than relying on someone else’s shell script. Doing so provides much better advantage in the long run.
$ head -3 /usr/bin/ssh-copy-id
#!/bin/sh
# Shell script to install your identity.pub on a remote machine
# Posted on 23-Aug-07 at 10:38 pm
FOSSwire » Bullet proof your server #2 - SSH wrote:
[…] Once that’s done, you need to copy your key to the server. […]
# Posted on 05-Jan-08 at 5:07 pm