Persistent SOCKS-proxy using SSH on Linux in single line

2022-09-05

In Linux you can simply use your remote host as SOCKS5-proxy. To do this run the following command in your terminal:

while true; do ssh ServerAliveInterval=60 -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -C2qTnN -D 1080 user@host; sleep 15; done

Then run in another terminal window:

curl --socks5-hostname 127.0.0.1:1080 https://ipinfo.tw/ip

It should print external IP address of a remote host being used as a SOCKS proxy.

You can set up 127.0.0.1:1080 as SOCKS5-proxy in your favorite browser as well.