macOS Terminal, Connect to SSH using Socks Proxy

5.5k Views Asked by At

I have been using this command to connect Terminal to my local SOCKS5 Proxy:

export http_proxy=socks5://127.0.0.1:8070 https_proxy=socks5://127.0.0.1:8070 && curl ifconfig.me;

My IP is correct according to ifconfig.me, so port 80 and 443 work fine, but when I use SSH, I'm not connected through the proxy.

Is there a simple way around that?

2

There are 2 best solutions below

0
On BEST ANSWER

I was able to connect ssh via shadowsocks with netcat:

 ssh -v -o 'ProxyCommand=ncat --proxy-type socks5 --proxy 127.0.0.1:1086 %h %p' -p22 username@ip

You can add it to ~/.ssh/config

Host *
     ProxyCommand=ncat --proxy-type socks5 --proxy 127.0.0.1:1086 %h %p

netcat isnt avaliable in MacOS by default, you need to install:

brew install nmap
0
On

One can also use nc which is now included in MacOS. On the command line:

ssh -o "ProxyCommand=/usr/bin/nc -x socks_proxy:1080 -W %h:%p " ssh_host

Or in the ~/.ssh/config file (change the Host entry to suit your needs) e.g To use the proxy all hosts:

Host *
  ProxyCommand /usr/bin/nc -x socks_proxy:1080 %h %p

Then you can just connect using:

ssh ssh_host