0

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?

4
  • What walls are those?
    – muru
    Jan 15, 2018 at 3:20
  • 1
    I 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. Jan 15, 2018 at 3: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. Jan 16, 2018 at 4:39
  • 1
    Possible duplicate of Easiest way to copy ssh keys to another machine? Sep 17, 2019 at 14:01

1 Answer 1

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'
1
  • 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? Jan 16, 2018 at 4:42

You must log in to answer this question.

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