Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two public keys, one for some servers and one for others. How do I specify which key to use when connecting to a server?

share|improve this question
up vote 15 down vote accepted

Assuming you're on a Unix/Linux environment, you can create or edit the file ~/.ssh/config.

That config file allows you to establish the parameters to use for each host; so, for example:

Host host1
  HostName <hostname_or_ip>
  IdentityFile ~/.ssh/identity_file1

Host Host2
  HostName <hostname_or_ip2>
  User differentusername
  IdentityFile ~/.ssh/identity_file2

Note that host1 and host2 can also be not hostnames, but rather labels to identify a server.

Now you can log onto the to hosts with:

ssh host1
ssh host2
share|improve this answer
You can also use -i <keyfile>, but I'd definitely recommend the config file method in the general case. – womble Jul 30 '11 at 8:43
I tried this but I keep getting prompted of the passphrase for my key. Even when I enter the passphrase correctly, the ssh login doesn't work. I tried using a blank passphrase too – Hamman Samuel Feb 29 at 20:27

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.