Ssh – How to connect to a server behind an socks5 proxy through SSH on mac/linux

sockssshunix

I am using the ssh to try to connect to a server behind on remote network. That server is behind a socks5 proxy on the same network. The port of the proxy server is 1080 and the ssh port is 22. However this fails. The debug says that connection is refused on port 22.

I thought it was necessary to install corkscrew so it installed it with homebrew and used this link as a reference

debug1: Reading configuration data /Users/jason/.ssh/config
debug1: Applying options for XXX.XX.XX
debug1: Reading configuration data /etc/ssh_config
debug1: Executing proxy command: exec /usr/local/bin/corkscrew proxy.server 1080 XX.XXX.XX.XX 22
debug1: identity file /Users/jason/.ssh/identity type -1
debug1: permanently_drop_suid: 501
debug1: identity file /Users/jason/.ssh/id_rsa type 1
debug1: identity file /Users/jason/.ssh/id_dsa type 2

Best Answer

 ssh -o ProxyCommand='nc -x 127.0.0.1:30000 %h %p' user@destination.com

where 127.0.0.1:30000 is the socks5 proxy. Credit: Jethro Carr