views:

703

answers:

4

Hi guys,

I'm working on Ubuntu and want to use multiple private keys to connect to different servers or different portions of the same server (My uses are admin of server, admin of git, and normal git usage within the same server). I tried simply stacking the keys in the id_rsa files to no avail.

Apparently the way to do this is use the command ssh -i <key location> [email protected]. That is quite cumbersome.

Any suggestions as to how to go about doing this a bit easier?

Thanks all, Justin

+1  A: 

Use ssh-agent for your keys.

Tuomas Pelkonen
+8  A: 

From my .ssh/config:

Host myshortname realname.example.com
Hostname realname.example.com
IdentityFile ~/.ssh/realname_rsa # private key for realname

Host myother realname2.example.org
Hostname realname2.example.org
IdentityFile ~/.ssh/realname2_rsa

And so on.

Randal Schwartz
Thanks Randal! I did some digging into the .ssh/config and found this: http://github.com/guides/multiple-github-accounts Pointed me in the right direction.
Justin
+1  A: 

foo:~$ssh-add ~/.ssh/xxx_id_rsa

make sure you test it before adding with:

ssh -i ~/.ssh/xxx_id_rsa [email protected]

if you have any problems with errors sometimes changing the security of the file helps chmod 0600 ~/.ssh/xxx_id_rsa

This is the most succinct and elegant solution in my opinion. Worked like a charm!
artur
A: 

The answer from Randal Schwartz almost helped me all the way. I have a different username on the server, so I had to add the User keyword to my file:

Host           friendly-name
HostName       long.and.cumbersome.server.name
IdentityFile   ~/.ssh/private_ssh_file
User           username-on-remote-machine

Now you can connect using the friendly-name:

ssh friendly-name

More keywords can be found on the OpenSSH man page. NOTE: Some of the keywords listed might already present in your /etc/ssh/ssh_config file.

peron