2

How could I route my SSH traffic through shadowsocks?

I am connecting from behind the Great Fire Wall to a server using shadowsocks. I would like to make outgoing SSH connections but I am concerned that SSH traffic could be identified and so result in my connection getting shutdown. Hence, I would like to be able to route the SSH traffic through the SOCKS5 proxy that I already have working.

Where do I start to achieve this? I assume I need to create a virtual network adaptor that can present a range of ports from which the output is routed over the SOCKS5 proxy somehow?

6

If your configuration of shadowsocks is:

  • local address : 127.0.0.1
  • local port : 1080
  • server ip 42.42.42.42

change for your own configuration

sudo apt install connect-proxy

Edit your ~/.ssh/config

# Outside of the firewall, with HTTPS proxy
Host 42.42.42.42
  ProxyCommand connect -H 127.0.0.1:1080 %h 22
## Inside the firewall (do not use proxy)
Host *
  ProxyCommand connect %h %p

Now you can try:

ssh username@ipserver

check ip connection

netstat -tn 2>/dev/null

normally you can see something like that

Connexions Internet actives (sans serveurs)

Proto Recv-Q Send-Q Adresse locale          Adresse distante        Etat       
tcp        0     68 69.69.69.69:22        42.42.42.42:42800      ESTABLISHED

More skills

Add this script to your ~/.bash_profile.

SOCKS5

export http_proxy=socks5://127.0.0.1:1080
export https_proxy=socks5://127.0.0.1:1080

OR

HTTP(S)

export http_proxy=http://127.0.0.1:1080
export https_proxy=https://127.0.0.1:1080

if you want setup webconnection for your Web browser

Gui way (gnome)

  1. setting
  2. network
  3. proxy server
  4. enter your configuration
  5. don't forget to disable proxy for localhost

enter image description here

or just add all proxy redirection to your env

env | grep -i proxy

must be return

HTTP_PROXY=http://127.0.0.1:1080/
FTP_PROXY=http://127.0.0.1:1080/
ALL_PROXY=socks://127.0.0.1:1080/
NO_PROXY=127.0.0.1,localhost
HTTPS_PROXY=http://127.0.0.1:1080/
https_proxy=http://127.0.0.1:1080/
http_proxy=http://127.0.0.1:1080/
no_proxy=127.0.0.1,localhost
all_proxy=socks://127.0.0.1:1080/
ftp_proxy=http://127.0.0.1:1080/

if you just want config curl through shadowsocks

export socks5=socks5://127.0.0.1:1080

and

curl api.ipify.org

For Git

git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
  • I'd like to add a note - if you are doing SSH for a user@my-server ( like when connecting to EC2 in the default way) then replace the server IP with the part at my-server – tt_Gantz Oct 17 '18 at 3:01
0

There is an easier way, use a match directive in your ssh config file:

Match Exec "nc -z 127.0.0.1 1086"
     ProxyCommand nc -X 5 -x 127.0.0.1:1086 %h %p

This directive will execute every time you ssh (Matches everything). First it tries to connect to your shadowsocks proxy using nc: the -z option just means to check the port with no IO. My ssocks proxy runs on port 1086. If it's running, then set a ProxyCommand, if it doesn't, don't, and connect normally, without a proxy.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.