How to configure svn+ssh client for multiple hosts with different keys

I use svn+ssh to access different repositories that are stored on servers on which I am not able to install svn access through the web server. Up to now I have defined a different svn+FOO protocol in my ~/.subversion/config for each repository. It looks something like this
foosh = $FOO_SSH ssh -q -l sidney -i /home/sidney/svnkeys/foosvn
That lets me checkout that repository using a svn+foosh://hostname.example.com URL.
The disadvantage is that I find using all those different protocols ugly.

I have just found out how to configure my client computer so I can continue to use svn+ssh with all the different hosts and automatically ssh to the correct host with the correct key.

The trick is to define a nickname to represent the host that the repository is on. In this example, let’s say that I will call it foo. Then my svn command for a checkout will begin svn co svn+ssh://foo/ and so on. To make that work I place a section in my ~/.ssh/config file that looks something like

Host=foo
User=myusername
hostname=hostname.example.com
port=22
IdentityFile=~/svnkeys/foosvn

This tells ssh that when I do an ssh login to a host name ‘foo’ actually login in to myusername@hostname.example.com and use the private key file specified by the identityFile option.

This is a much simpler setup than I had before. I have found many examples on the web about how to set up the public key on the server in the ~/.ssh/authorized_keys file with the “command” prefix that makes login with that key only run svnserver tunneling as a specific user. But I have not yet found anyone explaining this trick to avoid having to define a different svn+FOO protocol for each such repository.

Leave a Reply

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