Deadly simple sock proxy via ssh tunnel

Deadly simple sock proxy via ssh tunnel

You are in front of PC A, for e.g. your company firewall

PC A is under a network with a firewall that blocks outbound traffic to some websites.

You also have a public server (PC B) that is not under any firewall (or the firewall rule is setup by yourself.

There is a way that allow you to view the blocked website. With the following ssh tunnel you can use your browser under PC B's name from PC A

In PC A's command, execute

autossh -o "ServerAliveInterval 30" -o "ServerAliveCountMax 100" -D 1234 -CqNfT sammy@example.com

Command explanation

  • autossh: same command interface as ssh, however autossh automatically restarts the command if it its terminated. autossh need to manually be installed. This command can be replaced with ssh.
  • o "ServerAliveInterval 30": for each 30 seconds, send a ping package to server in order to prevent the ssh connection from being terminated due to inactivity.
  • -o "ServerAliveCountMax 100": number of server alive messages sent when the server does not response, before terminating the connection.
  • -D sock channel port specifier
  • -C: compress data
  • -q: quite mode, no warning
  • -N: open SSH connection with no command to be executed
  • -f: run background
  • -T: do not allocate a TTY-terminal, save a tiny amount of memory

Now your localhost serves as Sock proxy server at port 1234

Open firefox -> preference -> network setting -> Proxy -> manually Sock host. And set

Host: localhost
port: 1234

For Chrome (mac), execute http_proxy=socks5://localhost:1234 open -a '/Applications/Google Chrome.app'


To open this sock connection whenever your PC startups. Refer to this blog post to setup a startup script.

Happy coding! <3