August 31, 2012 | Posted in:Uncategorized

This post is more of a note to myself more than anything else but finding the answer to this problem has been a thorn in my side for a while so I have decided to write it down for future reference.  It may serve as something useful to someone else as well so I am publishing this in my blog too.   Here is the basic issue:  I want to read/checkout/commit/whatever against a remote subversion repository using ssh+svn.  To do this I should be able to use a simple command:

$ svn co svn+ssh://wally@192.168.1.100/var/svn/repo
svn: E210002: Unable to connect to a repository at URL 'svn+ssh://wally@192.168.1.100/var/svn/repo'
svn: E210002: To better debug SSH connection problems, remove the -q option from 'ssh' in the [tunnels] section of your Subversion configuration file.
svn: E210002: Network connection closed unexpectedly

As long as the port for ssh is the default (port 22) then there is no problem and life is good.  As you can see above this is not the case for me.  Why? Well, for some crazy reason (security in my case) the port for ssh has been changed from the default port.  Finding the right key words to Google might be elusive and, like me, you will eventually be kicking and screaming at the computer asking why it hates you so much.  To fix this problem one would think that you could specify the port to use in the URL like so:

$ svn co svn+ssh://wally@192.168.1.100:2222/var/svn/repo
svn: E210002: Unable to connect to a repository at URL 'svn+ssh://wally@192.168.1.100:2222/var/svn/repo'
svn: E210002: To better debug SSH connection problems, remove the -q option from 'ssh' in the [tunnels] section of your Subversion configuration file.
svn: E210002: Network connection closed unexpectedly 

Using the typical pattern for URL format (protocol://user:host:port/path) I expected the above command to work but at least with my svn client this is not the case.  I do remember spending some time researching this quirk and I believe that there are some differing implementations of the supporting svn libraries and basically specifying the port in this manner is not supported.  FYI – the client I am using is the command line subversion tools available via Cygwin.

So how do I get around this irritating problem?  First things first – read the error message for clues.  I did not initially realize this but the hint of “[tunnels] section of your Subversion configuration file” is exactly what we need to use to in order work around this issue.  It should be obvious that Subversion has a handy dandy configuration file that allows for tweaking of run-time settings but I have usually been fine with the out-of-the-box defaults.  Using svn over ssh is relatively new to me in my development process (I have usually accessed svn repositories over http or https) so using tunneling like this was new as well.  After gleaning the necessary configuration from the web I added two lines to my Subversion configuration file:

$ cat $HOME/.subversion/config
[tunnels]
sshtunnel = ssh -p 2222

That’s all that is needed really. This defines a new tunnel that I can use with svn and specify whatever I want – here I just specify the different port. Now I can connect to my remote subversion repository just like I wanted in the first place but with just a small twist:

$ svn co svn+sshtunnel://wally@192.168.1.100/var/svn/repo

Many thanks to Per Olsen of Denmark for being the blog where I finally found the answer to this problem.

Reference: http://www.techper.net/2009/01/11/changing-port-number-of-svnssh-subversion-protocol/

3 Comments

  1. James Spencer
    August 9, 2013

    The only thing I can say is, “Thank you very, very, much! “. This saved me after several hours of hair pulling.

  2. Pedro
    May 19, 2014

    I had a similar problem, and the root cause was a bad permission. I need to fix ~/.ssh/config to 600 and the public key also to 600

  3. Alain SENG
    July 30, 2015

    Just … THANK YOU !!! Your post is a life savior for me. Now I got another problem but SSH issue is resolved !!

Leave a Reply


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*