I have an account at the Computer Science department at BYU where I go to school. I recently started a subversion repository there so that I could work on some class projects within the safety net of version control. That worked well until I realized it would be nice to work on a certain project at home. To accomplish this, my first thought was “How do I access my subversion repository from home?” Alas, it appears there is no centralized location at BYU for this sort of thing. CVS, yes; SVN, no. Back to square one.

My next thought was, “Well, alright then, I’ll just host my repository somewhere else.” No go. Unfortunately, outgoing packets on non-standard ports are (apparently) being dropped. Using the svn client to get an external repository just hangs.

Plan C—using a 2-hop ssh tunnel to access my private repository—turned out to be the winner. It was, however, more difficult than I thought. Especially since I didn’t know what a 2-hop ssh tunnel is.

So here’s a run-down of the process if, in an oddly similar situation, you’d like to do it as well:

  • Create a 2-hop tunnel to your account. This was necessary in my situation since the BYU Computer Science lab has a gateway machine to the internal network.
    ssh -f -N -l <ssh username> -L 51526:racquetball:22 -2 cs.byu.edu
    

    Where racquetball is the hostname of the computer on the inside of the network (the “end” of the tunnel), and cs.byu.edu is the gateway machine. Replace <ssh username> with your own ssh username. The “51526″ is the port number on your local machine to which you will connect from now on. This is the “beginning” of the tunnel.

  • Add a tunnel config entry to your .subversion/config file. If you’ve ever used subversion on your own machine, then you will already have a .subversion/config file in your home directory. Find the “[tunnels]” section and add your own protocol. This is what mine looks like:
    byussh = ssh -l <ssh username> -p 51526
    

    Once again, replace <ssh username> with your own username.

  • Finally, use the svn client to access your repository. Note that the path is the full path on the destination machine (e.g. racquetball in my case).

    svn ls svn+byussh://localhost/users/guest/d/<username>/subversion
    

    Replace <username> with your account user name.

In the above scenario, I am telling svn to ssh to a local port (localhost:51526) as another user (me, on the other network). The local port listens for ssh connections and tunnels them directly to the racquetball end point. At that point, the “svnserve -t” command is executed and the subversion repository is accessed almost as if it were a local file:/// style protocol. Note that there is no other svnserve daemon required in this case—it’s created on demand.