I work on Ubuntu and want to use multiple ssh keys to connect different serves. I have tried some different method but unluckily they have failed. How can I use multiple ssh keys?
Multiple Hosts Multiple Keys
Ssh config resides in .ssh/config file in user home directory. The magic is here.
Host cen1 cen1.example.com HostName cen1.example.com IdentityFile ~/.ssh/cen1_rsa User root Host ubu1 ubu1.example.org HostName ubu1.example.org IdentityFile ~/.ssh/ubu1_rsa User ismail
Hostname cen1.example.com is the hostname of the remote system. While connecting to this system with IdentityFile ~/.ssh/cen1_rsa configuration makes to use cen1_rsa as key.
Multiple Keys Same Host
This is usefull alternative for key usage too. We want to use multiple keys for same host. As we know ssh is tries related keys for hosts in sequence. We can define new keys with Identity configuration like below
Host ubu1 ubu1.example.org HostName ubu1.example.org IdentityFile ~/.ssh/ubu1_rsa IdentityFile ~/.ssh/ubu1bak_rsa User ismail
Here IdentityFile ~/.ssh/ubu1bak_rsa is added alternate private ssh for host ubu1.