public
Last active

  • Download Gist
ssh_tunnel_1.textile
Textile

Create a tunnel to github with the git default daemon port like this:

$ ssh -L9418:github.com:9418 myuser@myhomessh.com

And clone repositories replacing github.com with localhost, like so:

$ git clone git://localhost/someuser/someproject.git

If you want to preserve the “correct” metadata, there are several options


  1. replace localhost origin with github.com after cloning
    git remote rm origin
    git remote add origin git://github.com/someuser/someproject.git

  2. add github.com to your hosts file and point it to 127.0.0.1

  3. add github.com to your ~/.ssh/config:
    Host github.com
      HostName localhost
    
  4. use your favourite packet forwarder, example for Mac OS X:
    sudo ipfw add 00100 fwd 127.0.0.1,9418 tcp from me to github.com dst-port 9418

    and when you are done, don’t forget to remove it:
    sudo ipfw delete 00100

    (use caution, especially if you are using ipfw already and have rule 00100 in place)

Stuck behind a corporate firewall? Justin Bailey has a good guide. Scroll down for a *nix solution as well.

ssh_tunnel_2.textile
Textile

Git has a config option called ‘core.gitproxy’ which allows you to use a command to tunnel the git:// protocol, which would normally go over TCP port 9418. So in my case, I’ve got a couple off-campus servers that I can use SSH tunnels with. I set up the typical SSH-based SOCKS proxy, thusly (you can also use apps like Shimo to manage tunnels for you):

$ ssh -D 1080 tycho@hostname

NOTE: If you are using ssh shared connection(controlmaster/controlpath), you will have to disable it(forwarding is not yet implemented in shared connection)

$ ssh -S "none" -D 1080 tycho@hostname

Then I use the tools which I’ve made available in this git repository to make cloning with the git:// protocol tunnel through SSH run transparently.

To use the tools, you need to first compile ‘connect.c’ and install the ‘connect’ binary to somewhere in your PATH (/usr/local/bin should work for this). Modify the ‘gitproxy’ script provided in the repository for your configuration (if you use the same command I used above, it should work fine without any editing). Once done editing it, install it as well.

Now tell git about the gitproxy script you just installed:

$ git config --global core.gitproxy gitproxy

Or if you want to use it for a single repository, run the command without ‘—global’ while you’re inside the working tree of the repository.

Or if you want to use it temporarily, use

$ export GIT_PROXY_COMMAND=gitproxy

Once this is all done, you should be able to simply do a git clone without any special URL mangling:

$ git clone git://github.com/tycho/crisscross.git
Initialized empty Git repository in /Volumes/Development/crisscross/.git/
remote: Counting objects: 1322, done.
remote: Compressing objects: 100% (723/723), done.
remote: Total 1322 (delta 915), reused 874 (delta 586)
Receiving objects: 100% (1322/1322), 566.77 KiB | 60 KiB/s, done.
Resolving deltas: 100% (915/915), done.
$

Here's my writeup for getting read-write access via ssh through a firewall:

http://technuggets.tumblr.com/post/2584970503/accessing-github-with-ssh-through-a-firewall

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.