Easiest method to Copy SSH Keys of One machine to another machine in Linux

There have been several times where we need to copy the SSH keys.

Yasmin Bano , 24 March, 2020

For example, In my case I want common SSH Keys between my laptop and my office machine. When I tried to google it, the result surprised me by the over complications of methods to copy SSH keys.

So here I am sharing a few easiest methods we’ve used to copy SSH Keys from one machine to another.

Copy SSH Keys on a Real machine

This blog mainly covers this part. To copy SSH Keys from one machine to another real machine follow the below steps: * Open the Machine1 (e.g. your computer) and copy the .ssh folder to a USB stick or any other storage device. * Then Open your machine2 (e.g. your laptop).

Now to copy SSH keys you can follow any of the following methods:

Method 1 Using SSH-ADD
  1. Put the .ssh folder under ~/ or /home/$machine2. in machine2
  2. Run ssh-add on machine2.
  3. Now, what ssh-add does exactly. SSH-ADD is like a helper program for SSH-AGENT. SSH-ADD adds private key identities (from your ~/.ssh directory) to the authentication agent (ssh-agent) so that the ssh-agent can take care of the authentication for you. For more detailed information Click here.
  4. Now test the SSH keys on the machine2 (e.g. your laptop).
  5. If you still find issues then please check the permissions of .ssh folder and make sure that correct permissions are given.
File/Directory Permission
.SSH Folder drwx------
id_rsa -rw-------
id_rsa.pub -rw-r--r--

Method 2 Manually Copy SSH Keys
  1. Copy .SSH folder from the storage device to any location of machine2.
  2. Now generate new SSH Keys in machine2.
  3. The next step is to replace the contents of all files of the .SSH folder of machine2 one by one with machine1’s SSH keys.
  4. Using this method you don’t need to worry about permissions of SSH keys.

Copy SSH Keys on a Virtual machine

To copy ssh keys on a remote machine is pretty straightforward. You can follow this wonderful digital ocean’s tutorial on SSH Keys. That's it

If you’ve any suggestions or difficulties to set up then please write down in the below comment section.

Happy Coding !!

blog comments powered by Disqus