Git-over-SSH through Socks 5 Proxy on Windows

  • git • script • personal • work • it • tunnelling • windows • socks5 • proxy • english • utility • bash • ssh
  • 190 words

Because of my work, I use crappy M$ Windows in my office. And we are behind a bidirectional firewall.

So, how do you do if you need to pull/push code with Git-over-SSH in this scenario? You need a Socks 5 that passes the firewall, and some scripting.

First, you need to install:

Then, you need a script that connects to the Socks 5 server. Like: [sourcecode lang='bash']

!/bin/sh

Filename: /path/to/socks-gw.sh

This script connects to a SOCKS proxy using Connect.c

/path/to/connect.exe -S your.socks5.server:1080 $@ ```

A script that opens an SSH connection using the connection opened by the previous script: [sourcecode lang='bash']

!/bin/sh

Filename: /path/to/socks-ssh.sh

This script opens an SSH connection through a SOCKS server

ssh -o ProxyCommand="/path/to/socks-gw.sh %h %p" $@ ```

Finally, another script that you need to source in the same Bash session you are going to use Git: [sourcecode lang='bash']

!/bin/sh

Filename: /path/to/enablesocks5proxyforgit.sh

This script sets Git to use the SOCKS proxy

export GITSSH="/path/to/socks-ssh.sh" export GITPROXY_COMMAND="/path/to/socks-gw.sh" ```

Again, don't forget to source this script before using Git.

Thanks to ThreeBytesFull, from which I re-adapted the scripts to work on Windows.

comments powered by Disqus