Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 9 down vote accepted

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.

share|improve this answer
Oh, that is better. Nice one! –  jdw Oct 5 '11 at 20:55

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:


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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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