Getting SSH to connect through a SOCKS proxy
At work, one of the things that has never worked for me is being able to use SSH from my laptop. While Cocoa apps will get redirected properly, command-line apps try to directly connect and fail. I’ve been trying for months to fix it, but could never find any solution that worked. The problem is compounded by the fact that the tool to fix it is not very searchable, and doesn’t compile on OS X.
However, I now have the solution:
- Download connect-proxy.tar.bz2 from my website (which is a patched, compiled version of the Debian package), and unpack the archive
- If you’re on OS X, just copy “connect-proxy” to your /usr/local/bin, otherwise run “make clean && make”, then copy the file
- Go to your “~/.ssh” folder and create a file called config. Insert the following line:
Host *
ProxyCommand connect-proxy -R both -4 -S proxy.url:1080 %h %p
And now, you’re good to go! But what do those flags do? Here’s a description of some useful flags:
- “-R both” – try a DNS lookup directly, and if it fails, try asking the proxy server
- “-4/-5″ – SOCKS4/SOCKS5
- “-S/-H hostname:port” – SOCKS / HTTP-based proxy
- “-d” – Causes connect-proxy to spew out debugging information