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

Mark Shust
InstructorMark Shust
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 3 years ago

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.

Instructor: [00:00] 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.

[00:32] 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.

[00:56] 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.

[01:29] 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.

egghead
egghead
~ a minute ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today