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?


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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.