Dec
7
SSH via a Socks proxy on OS X with connect.c
Filed Under Computers & Tech, System Administration on December 7, 2005 at 5:05 pm
NOTE: tested on OS X 10.7 Lion, works fine!
These instructions are for setting up a mac to use connect.c
to get SSH through a SOCKS proxy. If you are not using OS X this may still be of some use to you because connect.c
will compile on Windows and *nix as well. If you’re in the NUIM oncampus accommodation and are having problems SSHing this could be the answer to your problems!
The first step is to get a copy of connect.c
and compile it. The website contains instructions for doing this on other platforms but for the mac use:
gcc connect.c -o connect -lresolv
This will spool out a ream of warnings but don’t worry about that.
Then you have to copy this to a folder in the path and set up the correct permissions:
sudo cp connect /usr/bin sudo chmod 555 /usr/bin/connect sudo chown root:wheel /usr/bin/connect
At this stage connect.c
is installed, you now need to tell SSH to use this proxy for any servers you want to connect to that is outside the campus.
To do this you need to add lines of this form to ~/.ssh/config
:
Host xxx.yyy.com ProxyCommand connect -a none -S socks.yyy.com %h %p
The example above is for connection to xxx.yyy.com, you’ll need pairs like this for each host you want to connect to. You should separate the pairs with a bank line.
That’s it, you can now ssh as normal and ssh will use the SOCKS proxy.
ssh [email protected]
hi there,
i’m trying to locate a copy of connect.c for osx – looks like you may have had a copy… could you repost?
cheers,
j
Hi Jamie,
I have a copy somewhere in work but I’m off on sick leave at the moment. When I get back in I’ll dig it up for you.
Bart.
thanks bart!
do you recall where you got it?
j
I got it from the link in the post which I see is not resolving anymore.
Bart.
found one on http://www.meadowy.org/~gotoh/ssh/connect.c and works as described. thx. well done.
Fantastic! Thanks Torben. I’ve updated my post to include the new link.
Bart.
[…] wrote a how-to in his blog. It works great on Mac OSX, but it’s working the same way on other […]
works like a charm, even with iphone modem!
Thanks a lot for the tut!
Thanks for posting this guide, saved me some time trying to compile Corkscrew (my usual weapon of choice) on OSX.
Hiya,
I also found out that you can do this with netcat which comes installed
ProxyCommand /usr/bin/nc -X 5 -x socksproxy:port %h %p
Cheers,
Matt
Matt: excellent comment, thanks for the information. I got this working with connect, but then changed to your netcat version which is simpler and built-in.
[…] Menggunakan connect: http://www.bartbusschots.ie/blog/?p=184 […]
Great, works! I am on location with only GPRS internet, low bandwidth, traffic limits, so i route everything through my home openwrt over ssh proxy.
ssh via proxy was last thing i looked!
This improved the quality of my life dramatically. Thank you so much.
If you are looking to do this from the command line without setting a special config, try this:
ssh -o “ProxyCommand /usr/bin/nc -X 5 -x localhost:2500 %h %p” [email protected]
That worked for me (using localhost:2500 as my SOCKS5 proxy)…
Thanks for this page and the other comments, which helped me arrive at this solution…!
Now I’m going to go make a shell function…