How to tunnel Web Browser using SOCKS5 through SSH

Mar 27, 2018

Let's considering you need to access some websites through an intranet or using some machine's IP you already have SSH credentials. You can use your SSH access to tunnel the trafic between your browser and your host.

Who can use it?

For Linux or Mac you only need to install the ssh. For example, if you're using Ubuntu you can install from apt install openssh-client.

If you have Windows 10 the best option is the WSL (Install the Windows Subsystem for Linux). Install the Ubuntu or SUSE on Windows and enjoy the same SSH features.

How to open SOCKS5 tunnel

The command below will connect to the port 22 (default SSH port) on MY_HOST_IP and open SOCKS5 access on local machine's port 1080. So you need to add port 1080 as SOCKS5 proxy on your browser.

ssh -D 1080 -f -C -q -N -p 22 MY_USER@MY_HOST_IP

How to use SOCKS5 on browser

Go to the browser setting > proxy setting > set the SOCKS5 as your default browser proxy:

  • domain: localhost
  • port: 1080
  • user: empty
  • pass: empty

Remember you need to keep the SSH command running while you use the SOCKS5 tunnel.



Luiz Felipe F M Costa

I am a quality engineer at Red Hat / Ansible. I love automation tools, games, and coffee. I am also an active contributor to open-source projects on GitHub.