2013-06-29

Manage multiple SSH private keys

There are 2 ways to manage multiple SSH private keys.

Step 0. Create a file named ~/.ssh/config

Step 1-1st, SSH can be configured with both host names and their identity files.

Host server1.remote.host
IdentityFile ~/.ssh/server1.remote.host.privatekey
Host server2.remote.host
IdentityFile ~/.ssh/server2.remote.host.privatekey

Step 1-2nd, SSH can be configured with a per-user configuration file.

$ vi config
Type the followings...

IdentityFie ~/.ssh/id_dsa_%h_%r
IdentityFie ~/.ssh/id_rsa_%h_%r
IdentityFie ~/.ssh/id_dsa
IdentityFie ~/.ssh/id_rsa

Save and quit.

$ssh username@remote.host

=> SSH client will try to read the private key at one of the following files
~/.ssh/id_dsa_remote.host_username
~/.ssh/id_rsa_remote.host_username
~/.ssh/id_dsa
~/.ssh/id_rsa