I used to have old laptop with Ubuntu desktop 18.04 and dell server with Ubuntu server 18.04. On the laptop and server was installed ssh keys and I could connect to server without password. Now I got new laptop with installed Ubuntu Desktop 18.04 on it, but can not connect to server through ssh. I have files private / public keys. How can I install them on my laptop to get connection with server?

  • Do you still have access to the old machine?
    – terdon
    Sep 25, 2019 at 8:40
  • Yes I do have access. Sep 25, 2019 at 9:11

2 Answers 2


You don't "install" the keys to use ssh, you just reference the private key. For example:

ssh -i ~/my_private_key_file my_user_name@my_server_name

Note that any time your username is the same on both your local and remote machines, you can eliminate your user name and just:

ssh -i ~/my_private_key_file my_server_name

It's even more convenient if you edit your ~/.ssh/config file and add:

Host any_name
    HostName my_server_name
    User my_user_name
    IdentityFile ~/my_private_key_file

If you've done the above, then you can ssh in like this:

ssh any_name

You can also use keychain. Keychain lets you load your keyfile into memory like this:

apt install keychain


ssh-add my_private_key_file

With your key file loaded into memory as above, then you simply:

ssh my_user_name@my_server_name

You don't have to load the key into keychain each time. The key will stay in memory even when you close the terminal from which you ran it. You only lose it when you log out or reboot.

And finally, the "dream setup" is this:

Load your keyfile into keychain when you first log into your local machine.

Add the following into your .ssh/config file (notice the absence of the "Identity File" line)

Host any_name
    HostName my_server_name
    User my_user_name

Then ssh by:

ssh any_name

If you still have access to the old machine, just copy the ~/.ssh directory to the new machine and everything should work just as it did before. For example, if you can ssh (with a password) from the old machine to the new one, just run

user@oldMachine $ scp -r ~/.ssh user@newMachine ~/.ssh

If not, just copy it using a USB stick or even email it to yourself. Once you have the ~/.ssh directory copied, everything should work as it did before.

If you cannot do this for some reason, setting up passwordless ssh again is trivial. Just follow the instructions in this answer: https://askubuntu.com/a/46935/85695.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .