6

I have a new machine (H1) and I would like to copy my ssh keys over from an old machine (H2). How can I do this?

From Googling the answer seems to be ssh-copy-id: the problem is that I don't have ssh access from H2 to H1.

Can I literally copy the entire contents of ~/.ssh from H2 onto H1 via a USB stick, or will that cause problems?

1
  • I had almost the same question, answer here.
    – Mark
    Sep 3, 2018 at 22:50

3 Answers 3

4

You can copy the keys themselves over using any method, even copying the contents of the keyfile and pasting it into the 'authorized keys' file on the remote server will work.

I wouldn't recommend copying ~/.ssh over, better to just copy only what you need.

Edit...to clarify...

Copying the whole .ssh folder will result in moving the "known hosts" and "authorized_keys" directories onto the remote server, and sometimes the keys are stored elsewhere anyway. Generally, this is not good practice as it makes it much harder to keep track of what has access to what etc. Find the key you need to copy over by checking the IdentityFile line in /etc/ssh/ssh_config, then simply paste the contents into ~/.ssh/authorized_keys file on the remote server.

1

I followed this when I needed to do the same thing: Easiest way to copy ssh keys to another machine?

Long and short, ssh-copy-id [email protected] should do what you want.

2
  • 1
    Thanks but as the question says, I don't have ssh access to the second machine. I need to copy files across manually.
    – Richard
    Jan 6, 2015 at 10:56
  • Apologies, that'll teach me to scan-read things in a hurry :(
    – Fazer87
    Jan 6, 2015 at 11:01
1

You can simply copy the entire ~/.ssh folder to the another machine and you will be able to ssh to the remote machine S1 from H2.

However, if one private key gets compromised you would have to regenerate a key pair on both the machines. From the security point of view you should generate a new key-pair on every location.

Here is a better explanation: https://security.stackexchange.com/questions/102416/should-i-generate-new-ssh-private-keys-for-each-machine-i-work-from/102419#102419

You must log in to answer this question.

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