Using multiple ssh keys on Mas OS X Mountain Lion

Many times we need to use different keys to connect to different hosts. This can be very easily done in Mac OS X or Linux.

For instance if we have two private keys generated: id_rsa, id_rsa2.
We just need to edit the file “~/.ssh/config” or create it if it doesn’t exist.

vi ~/.ssh/config

Then add the hosts and authentication method:

Host www.EXAMPLE1.COM
Hostname www.EXAMPLE1.COM
User YOURUSERNAME
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa

Host www.EXAMPLE2.COM
Hostname www.EXAMPLE2.COM
User YOURUSERNAME
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa2

Leave a Reply

Your email address will not be published. Required fields are marked *