Video Lesson: Copy an SSH key to a remote server with ssh-copy-id

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

Learn how to configure public key authentication for secure passwordless access to remote servers.


Lesson Content

Once you have generated your SSH private and public keys, copy the public key to the remote server you want to authenticate against. The ssh-copy-id helper command handles this for you:

ssh-copy-id username@remotehost

Replace username with the remote user and remotehost with the server's IP address or hostname. The command will most likely prompt you for the remote user's password. After you enter it, ssh-copy-id adds your public key to the remote server.

Confirm that key-based authentication works by connecting to the server:

ssh username@remotehost

You should now connect without entering a password.

The ssh-copy-id command is a helper script that adds your public key to a specific file on the remote server. To see where the key is stored, connect to the server and move into the .ssh directory in the remote user's home directory:

ssh username@remotehost
cd ~/.ssh

The .ssh directory contains a file named authorized_keys. This file contains the public SSH keys that are allowed to authenticate as that user. Display its contents to confirm that your key has been added:

cat authorized_keys

To allow another user to authenticate to the server, copy their public key and add it as a new line in authorized_keys. The user can then connect as soon as they have the private key associated with that public key.

Maggie

Hey, I'm Maggie! 👋

Ask me anything.

Want to chat with Maggie?

Log in for AI tutor access.

Comments

Join the discussion!

Notes

Keep track of what you learn!