Wednesday, November 26, 2008

Accessing Subversion via SSH on a non-standard port

This may be common knowledge, but it took me a few minutes to figure out and I didn't want to have to spend a few minutes again in the future when I forget how to do this months down the line :).

There are two, somewhat easy ways to configure different options to SSH for SVN. The first option lets you make the options specific to SVN access; in other words, the options you use to access the SSH server will only affect SVN access. The second lets you make those options standard across any SSH access you make to that target server.

Let's say I have a server called "reposerver" that has SSH listening on port 12345. The SVN repository there is under "/var/svn/repos" and contains a project called "test-project". To check out that project via SVN+SSH, here's what you need to know:

Option one:

Basically, in your home directory (on a Linux system), there's a file .subversion/config. In that config file, there's a section called [tunnels]. Edit that section so that it has an entry like this:

[tunnels]
reposerver = $SVN_SSH ssh -p 12345

The "reposerver" part could be anything; I just named it the name of the server so it'd be easy to remember when I have to use it in a later step. What the rest of that entry does is call your SSH command with any of the normal SSH options, so if there are other options you'd normally use, you can also put them there.

Finally, when you're done with that file, save it. Then attempt to check out a project from your SVN server. Normally, you'd type "svn+ssh" as the protocol portion of the URL. But this time, you'll use the name of the "tunnel" you defined in your SVN config file:

svn co svn+reposerver://reposerver/var/svn/repos/test-project


It would definitely be nice if SVN supported passing ports along in the normal way URLs do (ie. http://server:port), but at least this gives you some level of configurability with different options in accessing the repository. In fact, you could, for example, use a different SSH implementation, or RSH, or whatever you wanted to do.


Option two:

You can edit the .ssh/config file in your home directory. Basically, you'd add a "Host" entry, and beneath that put any options you want to use whenever you access that host via SSH. For our example, the entry might look like this:

Host reposerver
Port 12345

Once you add the options you want to your .ssh/config file (check out the SSH2 client config man page for other options and more information), when you attempt to access SVN on the SSH server, those options will be passed on, too. So our checkout command would look like this:

svn co svn+ssh://reposerver/var/svn/repos/test-project

Note, this time we're using the normal "svn+ssh" as the protocol; you don't need to worry about any "tunnel" names or anything like that, and that's the advantage to this approach: you don't need to remember anything out of the ordinary. However, if somehow you want different options for SVN SSH access and regular SSH access, then option one above will probably be better for you.