Copying Public Keys to Remote Servers

Add the public key to the remote server file at $HOME/.ssh/authorized_keys. Various approaches are available for setting up the contents of this file. You can run ssh-copy-id or manually configure the file, as shown in the following sections.

Run ssh-copy-id

For systems with password authentication enabled, you can copy the public key from the client system to the remote server using the ssh-copy-id command. The tool also sets the permissions of $HOME/.ssh and $HOME/.ssh/authorized_keys appropriately.

  1. Use the ssh-copy-id command to append the public key in the local $HOME/.ssh/id_sshkey.pub file to the $HOME/.ssh/authorized_keys file on the remote system, for example:

    ssh-copy-id remote_user@host
  2. When prompted, enter the password for the remote system.

For more information, see the ssh-copy-id(1) manual page.

Manually Setting the authorized_keys File

If you don't have access to the ssh-copy-id command or are unable to access the system remotely with a password, you must populate the $HOME/.ssh/authorized_keys file manually.

  1. Copy the contents of the public key file $HOME/.ssh/id_sshkey.pub, on the client system and append the contents to $HOME/.ssh/authorized_keys on the server system.

  2. Ensure that the permissions of $HOME/.ssh and $HOME/.ssh/authorized_keys are set correctly on the server system.

  3. On the remote system, output the $HOME/.ssh/authorized_keys file:

    cat .ssh/authorized_keys
  4. Note whether the key entry is included in the output. For example, an entry might appear as follows:

    ssh-key AAAAB3NzaC1yc2EAAAABIwAAAQEA6OabJhWABsZ4F3mcjEPT3sxnXx1OoUcvuCiM6fg5s/ER
    ... FF488hBOk2ebpo38fHPPK1/rsOEKX9Kp9QWH+IfASI8q09xQ== local_user@local_host