The quickest way to keying an SSH login

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:


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.

Avatar for jacob Jacob Peddicord -

Jacob is a web developer, student, and programmer from Ohio. He is a staff member at the Ubuntu Forums and is most likely a fanboy of the distribution. He loves to write in code and words, play video games, and rant about topics most would have abandoned long ago. Jacob uses GNOME and is never seen running stable software, much to the demise of his laptop.

Home » Articles »

Discussion: The quickest way to keying an SSH login

  1. Skavoovie (guest)

    # Posted on 22 August 2007 at 04:18 PM

    Why bother with another script?

    Just do it all via the command-line:

    $ cat ~/.ssh/ | 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.

  2. Jacob (guest)

    # Posted on 22 August 2007 at 04:25 PM


    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.

  3. Skavoovie (guest)

    # Posted on 23 August 2007 at 10:38 PM

    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


    Shell script to install your on a remote machine

  4. # Posted on 05 January 2008 at 05:07 PM

    [...] Once that’s done, you need to copy your key to the server. [...]

Home » Articles » The quickest way to keying an SSH login