6

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?

bottles
  • 389
  • 1
  • 2
  • 11

2 Answers2

9

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.

ThatGraemeGuy
  • 15,473
  • 12
  • 53
  • 79
  • Oh, that is better. Nice one! – jdw Oct 05 '11 at 20:55
  • Host Key doesn't even have to exist. You can then declare Host below it for the real host name. That way, I can support multiple bitbucket.org accounts. Then I do things like `git clone bitbucket-Client1` and `git clone bitbucket-Client2`. – hopeseekr Sep 28 '15 at 14:43
3

Personally, I just name them appropriately. The old default of id_rsa certainly gets confusing. I name them so I know what they are for:

~.ssh/foo.com
~.ssh/foo.com.pub

I put foo.com.pub onto foo.com, then when I am connecting to foo.com, I use something like this:

ssh foo.com -luser -i~.ssh/foo.com

Or, in your case, something like

ssh Server_A -lusername -i/Users/username/.ssh/server_A
jdw
  • 3,855
  • 2
  • 17
  • 21