Monday, May 7, 2012

ssh with different private keys


SSH is probably one of the most used command line tools on linux. If you want to connect to another linux host it's the best way to go. It's also very secure and since security is really important nowadays many hosts on the Internet choose a public key authentication. This method is really smart because it only let people connect if they know their password AND their public key is in the "authorized_keys" file on the host.

For some time now i started a gitolite services at home. It's just for my own usage and thus not available over the Internet. Every script which i write is stored on the gitolite server.
This is quite handy because i can easily switch back to an older version of a script in case i made a mistake. Besides that I'm also forced to learn git which i really want to learn. 

Gitolite also have a public key authentication (on top of ssh), but since the service just runs on the local network and i don't wanted to enter my password every time, I've created a second key without a password.

Well now my problem was, ssh doesn't choose the right key for the git service so i searched the web for solution of my problem. A few hour later i found what i needed. It's easy. You just need a configuration file for ssh, which looks something like this:

Host tunafix
        Hostname tunafix
        User git
        IdentityFile ~/.ssh/gitolite_rsa

Host tunafix
        Hostname tunafix
        User michael
        IdentityFile ~/.ssh/id_dsa

The configuration is stored in file ~/.ssh/config. As you can see, depending on the username ssh choose different identity files. 

No comments:

Post a Comment