0

I've already generated a ssh key pair to connect to a remote machine, and now need to connect to a second/separate machine using the same method.

Should I continue using the same existing key pair (by copying the public key to the new machine)? Or should I create a new key pair and use that for the new machine?

If the latter, how should I do it on my local machine without interfering the existing key pair?

Simon Hughes
  • 195
  • 1
  • 1
  • 3
  • possible duplicate of [SSH: Do you use one private/public key pair for each remote machine? Or a single pair for all?](http://serverfault.com/questions/80478/ssh-do-you-use-one-private-public-key-pair-for-each-remote-machine-or-a-single) – TheCleaner Apr 25 '13 at 22:03
  • @TheCleaner, thanks for linking the other question. However, that question doesn't explain how to generate and use multiple key pairs without interfering each other. Could you shed some light on that aspect? – Simon Hughes Apr 25 '13 at 22:04
  • Sure: http://serverfault.com/questions/125672/is-it-possible-to-have-more-than-one-private-public-key-pair-per-user-for-ssh?rq=1 – TheCleaner Apr 25 '13 at 22:06
  • you can use option "-i" to use the second key, man ssh – Danila Ladner Apr 25 '13 at 22:07

2 Answers2

0

You just need to copy your existing public key to all hosts you want to connect to. Just use ssh-copy-id to setup your public key into the remote host.

$ ssh-copy-id user@machine

By default, ssh-keygen creates the authentication key in ~/.ssh/id_rsa or similar. You can however specify a different file name.

$ ssh-keygen /path/to/new/key

And ask to your ssh client to use this key for authentication.

$ ssh -i /path/to/new/key user@machine
Spack
  • 1,594
  • 13
  • 22
0

Generally, yes you can re-use SSH keys. I would personally consider what identities you have - e.g. Is the second system used for the same purpose? I have different keys for my work and personal servers for example.

Another question might be what would happen if your SSH keys were to be compromised? How secure would you like your security?

To answer the latter question, you can use an IdentityFile line in your SSH configuration (or specify the -i argument on the CLI) to use a different SSH key.

Craig Watson
  • 9,370
  • 3
  • 30
  • 46