svn+ssh with specific identity file

Here is a quick howto on using a config file to associate an SSH connection with a particular identity file. When I ssh directly from the command line, I can specify the port, identity file to use, and a whole raft of other options. However these options aren’t available when checking out from subversion using svn+ssh, and I needed to specify a particular private key to use. These instructions are for my kubuntu 9.10 installation but should work on every flavour of *nix as far as I know.

I was trying to check out using something like this:

svn co svn+ssh://[email protected]/desired/path

To do this, I created this file: ~/.ssh/config and in it I put the following:

host lornajane
HostName svn.example.com
IdentifyFile /path/to/private_key

Now I update my checkout syntax to make use of my alias rather than specifying the host directly, like this:

svn co svn+ssh://lorna@lornajane/desired/path

SSH realises that it should pull the host information from your local config file, and uses your HostName, IdentityFile and any other settings you specify (there are many options, see this reference for more information. For example I often use this for port numbers if I’m tunnelling my SSH between places, the possibilities are endless.

Hope this helps, if you’ve got anything to add then I’d be delighted to see a comment from you.

14 thoughts on “svn+ssh with specific identity file

  1. Hi Lorna,

    We’ve started using SVN externals quite a bit, which was an issue when we were using usernames within the URL. On Windows we’ve changed the ‘ssh’ tunnel for Subversion to use our own usernames, which isn’t great as it means we need different tunnel addresses for different config changes.

    Using the ‘User’ keyword in the ssh config in your example would solve this on Linux systems, however I’d be interested to know if any Window users have a way of setting this up on a per host level, rather than a per tunnel level.

    Is there a specific reason you don’t use the User keyword in your config?

    =D

  2. Dom: I can’t answer your windows question but hopefully someone else will! As for my username, no reason at all for it not being in the config. I usually specify everything in full, and I only used the config in this example to specify things that I couldn’t add into the svn_ssh command. The rest is still as it usually is purely out of habit I think, I don’t feel strongly either way.

  3. Hello,
    you solved my problem, I added the config file so that svn connects to an svn running into an EC2 instance.
    Strangely enough, though, in a Mac, with Firefox, Safari or Chrome I see nothing under the line
    “To do this, I created this file: ~/.ssh/config and in it I put the following:”, it didn’t matter in my case since just by adding IdentifyFile in the config file it worked.
    Thanks and regards,

    Pau

  4. Pau: thanks for your update, I’ve been having some problems with my geshi plugin “eating” some, but not all, code snippets in old posts. Glad the article was helpful :)

  5. > Now I update my checkout syntax to make use of my alias rather than specifying the host directly, like this:
    >
    > svn co svn+ssh://lorna@lornajane/desired/path

    A better way is to use svn switch instead of redo the check out of the repository:
    svn switch svn+ssh://[email protected]/desired/path svn+ssh://lorna@lornajane/desired/path path

  6. This was a new checkout, but thanks for your example using switch – I recently moved my SVN server between hosts so I’ve been “switching” a lot of checkouts lately. This is a good tip

  7. Nice tip! However ‘IdentifyFile’ should read ‘IdentityFile’ in original post.
    May be able to do similar by editting .subversion/config. Thanks.

  8. Thank you so much :)
    You solved my problem. Finally I found that I must put number of the port in the config file, like:
    [code]
    Host MyServer
    HostName myserver.com
    Port 1992
    IdentityFile ~/.ssh/mykey.pem
    [/code]

    Then I just need to run this command:
    [code]svn co svn+ssh://myuser@myserver/my/repository/path[/code]

  9. I have installed SVN server and all is working fine on svn commit, svn checkout and svn update if I have done the svn checkout using file:///var/www/svn/repos
    But when i do svn+ssh it gives authentication failed.

    svn co svn+ssh://[email protected]/var/www/svn/repos/xfer1.0/ mmt_live/
    svn: Authentication failed
    Killed by signal 15.

    But when i do svn co svn co file:///var/www/svn/repos/xfer1.0 it works fine.

    Any help what is wrong why i am getting this Authentication failed.

    • Check that you can SSH to that user@host combination first, then try again with the SVN once you have the SSH working. It sounds like you don’t have SSH access or it isn’t quite configured correctly.

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.