I just got a new computer and I connect to 3 different remote machines using ssh. They all have logging in with password turned off so I have to have a key. What is the best way to copy my newly generated key to these machines without having to take down my walls?
Asked
Active
Viewed 4,613 times
0
-
What walls are those? – muru Jan 15 '18 at 03:20
-
1I am assuming you no longer have the system with the old key on it? If you did it would be a simple matter of logging in from that to add your new public key to those hosts. If you don't, then I think you're out of luck. You'd have to get physical/console access to those remote machines some other way. – thomasrutter Jan 15 '18 at 03:35
-
I do have access to that computer, just don’t have a full understanding of how those keys are stored. I think the answer below is getting at your answer. – Chris Wendel Jan 16 '18 at 04:39
-
1Possible duplicate of Easiest way to copy ssh keys to another machine? – Trevor Boyd Smith Sep 17 '19 at 14:01
1 Answers
2
Depending on your OS, you can try:
ssh-copy-id username@host
To specify the key file use:
ssh-copy-id -i ~/.ssh/id_rsa.pub username@host
You may have to copy your public key to a computer that already has SSH access to the three machines, otherwise these commands won't work without asking for a password.
I find this is much easier than using my old method:
cat ~/.ssh/id_rsa.pub | ssh username@host 'cat >> .ssh/authorized_keys'

Jamie S
- 141
-
Awesome, I think this is what I was looking for. This was my initial thought but I wasn’t sure exactly how it would work. So copy my id_rsa.pub to my old computer and then copy that same file to the new computer? Are all public keys stored in one file? Or will I have to make sure I select the right one? – Chris Wendel Jan 16 '18 at 04:42