managing multiple ssh keys

Recently I wanted to connect to some remote server using different ssh keys. With the right ~/.ssh/config file this is easy and comfortable.


IdentityFile ~/.ssh/%h/%r/id_rsa  
IdentityFile ~/.ssh/%h/id_rsa  
IdentityFile ~/.ssh/id_rsa  

%h and %r are placeholder for host and remote-user. ssh foo@bar will first check if ~/.ssh/bar/foo/id_rsa exists, next ~/.ssh/bar/id_rsa and finally ~/.ssh/id_rsa.


Host github  
HostName 123.45.678.90  
User myuser  
IdentityFile ~/.ssh/123.45.678.90/id_rsa  

Instead of ssh myuser@123.45.678.90 the above config allows you to simply type

ssh github

You don’t need to remember all your IPs and remote-users any longer. For me this is a big time saver.

Please let me know if you have questions or suggestions. Either per @leifhanack or comment here.