Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Copy an SSH key to a remote server using ssh-copy-id


    Learn how to use the ssh-copy-id command to securely add your SSH key to a remote host. Find out what happens after copying a public key to the remote server, as well as manually adding keys to the ~/.ssh/authorized_keys file.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Instructor: Once you have generated your SSH private and public keys, the next step is to copy the public key to the remote server you wish to authenticate against. There's a simple helper command that makes this really easy, called ssh-copy-id. Let's ssh-copy-id followed by the user name that you which to SSH as, followed an @, followed by the IP address or the host name of the remote host. You'll most likely be prompted for a password.

    Once you type in your server password and hit enter, the SSH key will have been copied to the remote server. To confirm you can ssh into the remote server with your SSH key and without a password, just type ssh username@remotehost and hit enter. You should now be SSHed into the server without being prompted for a password.

    Since ssh-copy-id is just a helper script, let's find it what it's actually doing in the event we want to manually add keys for authentication in the future. After SSHing into the remote host, go into the .ssh folder within your home directory. Within that folder will be a file named authorized_keys. This file contains a list of public SSH keys which have been granted access for authentication. We can see that our public SSH key has been added to this file.

    To allow another to authenticate to the server, just copy and paste their public SSH key into this file and save it. Once complete, the user that has access to the associate private key will then have access to connect to this host machine.