Changing Port Number of svn+ssh Subversion Protocol

Most times, when we access subversion through the svn+ssh:// protocol, we are satisfied with the default behaviour, which is simply spawning ssh behind the scenes, and have it connect using the default port 22 of the ssh protocol.

But, sometimes this is not enough. In my previous post I just described how ssh is great for tunneling and port forwarding. To access a remote subversion server, which was hidden behind a firewall and two hops into the system behind it, I had to port forward a local port all the way to the ssh port 22 of the behind the firewall host. My local ssh port that was tunneled into the remote system ended up on a local port, say 12345.

So, how to tell subversion to spawn ssh with a config of port 12345, when accessing a svn+ssh://-like URL? Well, turned out to be quite easy.

Subversion has a local configuration file .subversion/config, which can be used for various, … hmm, configuration stuff :-) A cool thing is, that one can provide new protocols. So, with this configuration in .subversion/config:

sshtunnel = ssh -p 12345

I can use a subversion URL like this: svn+sshtunnel:// and subversion will spawn the given command with the port option.

Great tool – subversion.

January 11, 2009 · polesen · 20 Comments
Tags:  · Posted in: Tools

20 Responses

  1. ryan - January 23, 2009

    agreed… svn++

  2. Jaroslav K. - November 28, 2009

    Great! Works like a charm.
    Thank you for suggestion!

  3. Aftab Naveed - December 23, 2009

    Great post :-) I tried that with my hostgator account and it worked.

  4. Fahmi - February 17, 2010

    Thanks! this is helpful :)

  5. Leonardo - February 26, 2010

    It fixed my “svn: Network connection closed unexpectedly”.

  6. MoxFulder - June 14, 2010

    Thanks, that’s what the answer I was looking for.

  7. Yasen - October 20, 2010

    How about if I am using https to connect to the SVN repository?

    I am trying something like that
    // create remote port forwarding
    ssh -R 7711:localhost:443 -p 222

    // checkout from our server to the remote server
    svn checkout https://localhost:7711/svn/trunk /home/code

    But i get svn: Propfind of ‘/svn/trunk’: 405 Method not allowed (http://localhost:7711)

  8. polesen - October 21, 2010

    I am not sure about that. Haven’t done it with https.

    Are you sure about -R. Shouldn’t that be -L ? If I understand you correctly, you have svn server at running on port 443, and want to check out from it locally on 7711? If that is so, I believe it should read “-L”.

  9. Reginald - December 16, 2010

    So wheee do I put the configuration file? On the server or on the client?

  10. polesen - December 16, 2010

    On the client

  11. Jamie Gray - January 19, 2011

    Good tip! Another approach which may be easier is to just embed the port number into the URL, e.g.


    I don’t know whether all clients will be able to handle the port number in the URL in this format, but it works for mine. Putting the port number in the URL looks easier in general, but what I like about your approach is that it lets you change that port configuration in a central place, without having to touch any checked-out repositories. I can see this being handy if you’re in a situation where you have to mess around with your port tunneling situation frequently.

  12. Rick - January 24, 2011

    OK. Here’s how I fixed this (on Mac OS X, but fix should work on any client)

    This particular issue arises when you are using a non-standard port (let’s say 12001 for sake of example) for your SSH server.

    Apparently the SVN client experiences syntax errors when given a port address on a command line like this one:

    svn list svn+ssh://

    So, to fix this, you need to create a client-side config file for SSH like this:

    cd ~
    cd .ssh
    vi config (create a config file like the one that follows)

    Config file located in ~/.ssh/config:

    User username
    Port 12001

    Then, issue your svn+ssh command WITHOUT the port like this:

    svn list svn+ssh://

    That’s it!

    Hope that helps.

  13. Jiraiya - May 9, 2011

    The original fiddle with the subversion tunnel config didn’t work for me.
    However, the SSH trick with the config file worked perfectly!
    I was using the latest MacOSX 10.6
    Kudos to you! It saved me a lot of hassle.

  14. Leo Benitez - August 25, 2011

    hi, sorry! I dont understand where is the configuration for tunnels, server or client?? thanks!!!!

  15. polesen - August 26, 2011


    Locally/client. In $HOME/.subversion/config

  16. Aiham - November 14, 2011


    Thanks, I was able to specify the port through the SSH config.

  17. Paul Oldridge - February 19, 2012

    If you get the message “Killed by signal 15.” whenever you use this it’s because you need the -q flag which svn normally has by default for svn+ssh.

    sshtunnel = ssh -p 12345 -q

  18. Accessing a remote svn repository on a non-standard port | - July 1, 2012

    [...] Share and Enjoy: [...]

  19. Using a Non-Standard Port With Subversion » A Moment of Wisdom - August 31, 2012

    [...] Olsen of Denmark for being the blog where I finally found the answer to this problem. Reference: VN:F [1.9.20_1166]please wait…Rating: 0.0/10 (0 votes cast)VN:F [1.9.20_1166]Rating: 0 (from 0 [...]

  20. SVN unter Linux nutzen - ascii_ch - March 13, 2013

    [...] Ähnliche BeiträgeTortoiseSVN Port ändern unter WindowsSSH als Proxy-ServerSSH Public-Key Authentifikation einrichten SVN unter Archlinux installierenSSH unter Archlinux installierenZemanta /* Tagged Linux, SSH, SVN, Versionsverwaltung. Bookmark the permalink. « yaourt unter Archlinux installieren Troubleshooting: yaourt Unable to open file: /usr/local/etc/pacman.conf » [...]