Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I was able to setup ssh to use private/public key authentication. Now I am able to do

  ssh user@server1

And it logs on with the private key. Now I want to connect to another server and use a different key. How do set it up so

ssh user@server1

uses privatekey1

ssh user@server2

and uses privatekey2

share|improve this question
    
I have to ask, why do you need to use different private keys for the two servers? –  David Z Aug 11 '10 at 22:03
    
No real reason - ones a personal mythbox and the other is a work server and I didn't want to use my home key at work. –  Joshua Aug 12 '10 at 11:56

2 Answers 2

up vote 18 down vote accepted

There are a few options.

1) Load both keys into your ssh agent using ssh-add. Then both keys will be available when connecting to both servers

2) Create your $HOME/.ssh/config file and create a Host section for server1 and another for server2. In each Host section, add an IdentityFile option pointing to the appropriate private key file

share|improve this answer
1  
ssh agent was a great idea, also if I have both the public and private key files, ie key1 and key1.pub, in ~/.ssh it will automatically load them. –  Joshua Aug 12 '10 at 11:58

You can set this up in your ~/.ssh/config file. You would have something like this:

Host server1
IdentityFile ~/.ssh/key_file1

Host server2
IdentityFile ~/.ssh/key_file2

man ssh_config is a reference

share|improve this answer
3  
You can also specify User for each host to cut down on key strokes. Lastly when you're generating a new SSH key for each host with ssh-keygen make sure you actually enter an alternate key path. –  Marco Ceppi Aug 11 '10 at 20:49

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.