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

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

1 Answer 1

up vote 11 down vote accepted

Assuming you're on a Unix/Linux environment, you can create a config file in your ~/.ssh/ directory.

The 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>
  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
4  
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

Your Answer

 
discard

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.