Wednesday, April 30, 2008

Accessing a HostGator SVN repository via SVN+SSH on Windows

This information should be helpful to anyone trying to access an svn repository stored on a remote (shared) server which does not expose an svn server.

My host is HostGator (good speeds, reliable ssh, cgi-only, MyISAM-only, decent support, non-existent knowledgebase). HostGator runs SSH over port 2222 which presents a few problems when trying to use traditional methods to connect to an SVN repository via SSH.

For these steps you will need Putty. Just get the whole suite.

  1. Generate an RSA key using PuttyGen
  2. Copy the public key into your ~/.ssh/authorized_keys file on the server.
  3. Prepend your key with (so it's all on one line):
    command="/usr/bin/svnserve -t"

    This sets up svnserve to run in tunnel mode. The ramification of this is that you can no longer use this RSA key to auto-login on the shell. There is some information out there about creating an subdomain and only having this rule apply to that subdomain, which solves that problem. On *nix machines this involves adding a simple rule to your SSH keystore that says "use key X when connecting to and key Y when connecting to". Then you would have two entries in your authorized_keys file, one with the svnserve command for connections to using key X and one without for key Y.

  4. Now load your private key into Pageant
  5. Create a new Putty connection called

    • Set the the Auto-login username.
    • Ensure that SSH->Auth->Attempt authentication using Pageant is checked.
    • Create an SSH tunnel which forwards LOCAL port 22 to port 2222.

    SAVE the connection and then test it by opening it. You should be logged in without having to provide a password.

    SVN should now be working when you use TortoiseSVN (or a similar client I assume). However, svn from the command line will not work and will report "Can't create tunnel..."

    Now to get SVN working from the command line.

  6. Create an SVN_SSH environment variable with value (keep the quotes and use forward slashes):
    "C:/Program Files/PuTTY/plink.exe"

    SVN will now use plink to try to connect to the svn repository. This will only work if the domain of your svn root's URL is named the same as the Putty connection you created i.e.

If you find that you are getting errors when running "svn info" on a URL I found that version 1.4.2 works for Windows but 1.4.6 does not.


Anonymous said...

THANK YOU!! THANK YOU!! THANK YOU!! This was exactly what I needed. I never did get Tortoise to be happy, but I at least got the command line working with your tips in under 15 minutes, after hours struggling with this (and other tips I found that did not work).

Sebastian said...

Hello Karl, I'm also using HostGator and have a SVN access. Just now I contacted them to set up SVN on their shared servers. They mean that this is not included inside their current plans. So my question is: Do you have full access to the SVN commands on your HostGator account or are you somehow emulating and tunneling the SVN-commands from your machine?

Karl Varga said...

Hi Sebastian, I'm on a shared server. The Hatchling account I believe. I do have access to SVN commands from the command-line. They have SVN, although I don't see any mention of it on their account info page...probably it's something that is available but not supported. That means they may change it at any time. You get a 45 day money back guarantee, so you can always open an account and try it.

Walter Garcia Jr said...

Hi, I'm trying to setup a repository in Hostgator,

I could sure use your help.

Thank you in anticipation

Karl Varga said...

Sure Walter, I'll do my best. You can shoot me an email at kjvarga [at] gmail [dot] com.

Anonymous said...
This comment has been removed by a blog administrator.
Kris said...

Hi Karl

I'm setting up a repository on my hostgator server. This is really not my strongest point, I keep confusing myself :)

What is pageant? Did I miss something?

Blogger said...

Bluehost is ultimately the best web-hosting company with plans for any hosting needs.