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> login@server.example.com
That is quite cumbersome.
Any suggestions as to how to go about doing this a bit easier?
Use ssh-agent for your keys.
On Centos 6.5 running OpenSSH_5.3p1, OpenSSL 1.0.1e-fips, I solved the problem by renaming my key files so that none of them had the default name. My .ssh directory contains id_rsa_foo and id_rsa_bar but no id_rsa, etc.
Now, with recent version of git, we can specify sshCommand in repository specific git config file.
You can create a configuration file named
config
in your~/.ssh
folder. It can contain:This will allow you to connect to machines like this
Make sure you test it before adding with:
If you have any problems with errors sometimes changing the security of the file helps:
I had run into this issue a while back, when I had two Bitbucket accounts and wanted to had to store separate SSH keys for both. This is what worked for me.
I created two separate ssh configurations as follows.
Now when I had to clone a repository from my work account - the command was as follows.
I had to modify this command to:
Similarly the clone command from my personal account had to be modified to
Refer this link for more information.