SSH into a server with an alternate key

When you have more than one private key, you need to specify the add the alternate key for authentication. The preferred method is to do a:

ssh-add ~/.ssh/alternate_private_keyfile

 

However in certain cases, you may need to do this for each session. Or there may be cases where you dont have access permissions to execute this file on the server.  In such cases, you can directly add the key to the agent by adding the paramters for the key to a file ~/.ssh/config. Create this file if it doesnt exist.

emacs ~/.ssh/config

 

In the file, add the following line and modify it as per the key file path for your private key:

IdentityFile ~/.ssh/id_dsa_xda
IdentityFile ~/.ssh/sourceforge_droidzonedroidzone

Here, two keys are being added to the client.

The third way is to specify the keyfile with the ‘-i ‘ option while sshing or doing an scp. Tedious, and can be overcome by the method described above.

Note that after copying any key into .ssh/, you have to disable read/write access to the group and others by:

chmod 600 ~/.ssh/keyfile

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.