Sports Biomechanics Lab > Blog > Multiple SSH key pairs, some with passwords and some without
Personal tools

Multiple SSH key pairs, some with passwords and some without

by Jason Moore — last modified Apr 27, 2011 11:35 AM
Filed Under:

I needed to setup some ssh key pairs that could be used with cron jobs, thus not requiring a password. But I also needed to have passwords on some of my other server connections. This is how I did it.

I have several website that I use various cron jobs to download the most recent website backup. I use a either scp or rsync to do this. There were several resources that helped me figure that out:

You can find many more with search terms such as "cron", "crontab", "ssh", "rsync", "scp", etc.

I followed these instructions and ended up with a ssh public/private key pair that was not encrypted with password and was able to log into my web servers for the cron jobs without needing a password (you may want to set these us so that the user the connections from certain machines for certain purposes are limited in their permissions). The problem arose when I tried to log into some other servers that I have been using with encryption. I wasn't able to any more because of my new private key didn't match the public keys on those servers. I first tried to append multiple private keys into one private key file, but this didn't work. This solution for me was to create two key pairs, one with a password and one without. Then I created a config file for ssh in ~/.ssh/config that looks something like this:

Host server1
Hostname server1.org
User user1
IdentityFile ~/.ssh/id_rsa

Host server2
Hostname server2.com
User user2
IdentityFile ~/.ssh/id_rsa_no_pass

You should set up and entry for each server connection and set the IdentityFile to point to whatever private key file you want to use for that server. Now I have to give a password for server2 but not server1.

Document Actions
Add comment

You can add a comment by filling out the form below. Plain text formatting.

(Required)
Please enter your name.
(Required)
(Required)
(Required)
Enter the word