Linux – How To Organize and Use Multiple RSA Keys On Local Machine

authenticationlinuxrsassh

I have Server_A, Server_B, and Server_C.

I want to generate unique authentication keys for each, and organize them on my local machine running Lion like so:

  • Put server_A keys in Users/username/.ssh/server_A
  • Put server_B keys in Users/username/.ssh/server_B
  • Put server_C keys in Users/username/.ssh/server_C

When I connect to Server_A (or B or C), how do I specify the correct private key with which to authenticate my local machine?

Best Answer

You could use command-line options as jdw says, but the saner option is to configure ssh so that it knows to do this automatically.

Create or edit your ~/.ssh/config file and add the following:

Host Server_A
    IdentityFile ~/.ssh/server_A

Host Server_B
    IdentityFile ~/.ssh/server_B

Host Server_C
    IdentityFile ~/.ssh/server_C

Now whenever you ssh/scp to those servers, it will use the respective private key.