What is the Easiest Way to Copy SSH Keys to Another Machine?

In Linux, SSH (Secure Shell) is used to create the connection to the remote host login. It works on the cryptographic algorithm that builds the private and public keys. When an SSH key pair is generated, it needs to copy the SSH key to the remote host to add it to the authorized key.

This post will demonstrate the easiest method to copy the SSH keys to another machine.

Method 1: Through ssh-copy-id 

The SSH key is located in the folder “.ssh” file in the home directory that is accessible for our own user. The easiest method to copy the SSH key to the remote host is using the “ssh-copy-id”, type it in the terminal along with the remote hostname:

$ ssh-copy-id Henry@ubuntu

The command is described as:

  • The “ssh-copy-id” will copy the key file 
  • The “Henry@ubuntu” is the remote host in which SSH key file is copied.

Note: Make sure that the other machine/remote host contains the same sub-directory of “.ssh” in the home directory to copy the SSH key.

Alternative Method: Through scp Command

An alternative way to copy the SSH key file through the scp utility, use the following command syntax and specify the other machine/remote hostname:

$ sudo scp .ssh/id_rsa.pub user@hostname:

Let’s copy the file using the above syntax:

$ sudo scp .ssh/id_rsa.pub Henry@ubuntu:

The SSH key file has been copied to the 

Conclusion

In Linux, the easiest way to copy the SSH keys file to another machine is using the “ssh-copy-id” with the remote hostname. Alternatively, the scp command can also be used to copy the SSH key file to the remote host. This write-up has illustrated the easiest method to copy the SSH keys file to another machine.