Best way to use multiple SSH private keys on one client

Justin picture Justin · Mar 10, 2010 · Viewed 478.1k times · Source

I want to use multiple private keys to connect to different servers or different portions of the same server (my uses are system administration of server, administration 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 a straightforward way to do this is to 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?

Answer

Randal Schwartz picture Randal Schwartz · Mar 10, 2010

From my .ssh/config:

Host myshortname realname.example.com
    HostName realname.example.com
    IdentityFile ~/.ssh/realname_rsa # private key for realname
    User remoteusername

Host myother realname2.example.org
    HostName realname2.example.org
    IdentityFile ~/.ssh/realname2_rsa  # different private key for realname2
    User remoteusername

Then you can use the following to connect:

ssh myshortname

ssh myother

And so on.