Copy SSH Private Keys – How to Copy SSH Private Keys to Another Computer

ssh

I need to use another computer to access my ssh server. This is because a recently implemented vpn at my university doesn't work on my current computer and I have lost access to the server.

I ssh via encrypted ssh keys. Can I copy these keys to the new computer (on which the vpn works). I tried copying the id_rsa and id_rsa.pub files in the ~/.ssh folder but it doesn't recognize the keys and there is no prompt to input a password to decrypt the keys.

EDIT: I can't access the server to generate a new key pair for the new computer and am out of the country so can't physically access it.

Thanks.

Best Answer

Check the permissions and ownership of your private key file. From the manual,

These files contain sensitive data and should be readable by the user but not accessible by others (read/write/execute). ssh will simply ignore a private key file if it is accessible by others.

Typically the key files should look like this,

$ ls -l ~/.ssh/id_rsa*
-rw------- 1 benj benj 1766 Jun 22  2011 .ssh/id_rsa
-rw-r--r-- 1 benj benj  388 Jun 22  2011 .ssh/id_rsa.pub

which you can enforce via:

$ chown benj:benj ~/.ssh/id_rsa*
$ chmod 600 ~/.ssh/id_rsa
$ chmod 644 ~/.ssh/id_rsa.pub
Related Question