Forrest logo
back to the ssh-copy-id tool

ssh:tldr:4b38f

ssh: Copy the given public key to the remote.
$ ssh-copy-id -i ${path-to-certificate} ${username}@${remote_host}
try on your machine

The command ssh-copy-id is used to copy the user's public key to a remote server, allowing passwordless authentication for future SSH connections.

Here is the breakdown of the command:

  • ssh-copy-id: This is the main command that facilitates copying the public key to the remote server.
  • -i ${path-to-certificate}: This option specifies the path to the user's public key certificate. The ${path-to-certificate} should be replaced with the actual path on your local machine.
  • ${username}@${remote_host}: This represents the username and remote host where you wish to copy the public key. ${username} should be replaced with the desired username, and ${remote_host} should be replaced with the IP address or hostname of the remote server.

For example, if you have a certificate located at ~/.ssh/id_rsa.pub, and you want to copy it to the remote server with the username user1 and IP address 192.0.2.123, the command would look like this:

ssh-copy-id -i ~/.ssh/id_rsa.pub user1@192.0.2.123

Executing this command will prompt you for the password of the remote server's user. After providing the password, your public key will be appended to the ~/.ssh/authorized_keys file on the remote server. From that point onwards, you should be able to log in to the remote server via SSH without entering a password, using the corresponding private key stored on your local machine.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the ssh-copy-id tool