Setting-up SSH-tunnel for VPN?

6,485

Solution 1

The easiest why to tunnel all traffic through SSH similar to a VPN is to use the sshuttle package.

First, install the package:

sudo apt-get install sshuttle

Then connect to the SSH tunnel and redirect your default route to go through it:

sshuttle  -vv --dns -r username@sshserver[:port] 0.0.0.0/0

This will forward all TCP traffic through your SSH connection, including DNS requests. If you still want DNS handled locally, you can remove the --dns flag.

Solution 2

Create a tunnel

ssh -fND 7001 yourVPN

Open Chromium to use Proxy

chromium-browser --proxy-server=socks5://localhost:7001

Notes

  • 7001 is the port and can be changed, so long that they both match
  • You can also pass --user-data-dir=/tmp/someDir to chromium to use a different instance of Chromium
Share:
6,485

Related videos on Youtube

Baard Kopperud
Author by

Baard Kopperud

Updated on September 18, 2022

Comments

  • Baard Kopperud
    Baard Kopperud over 1 year

    I have a laptop running Ubuntu. I also rent a VPS running Ubuntu. I've bought a paid VPN-service, which I use on my laptop.

    I was wondering how I can set-up a SSH-tunnel or something similar, from my laptop to the VPS I'm renting, so I then can run VPN (from my laptop) "through" it (to the VPS), to the VPN-server. The reason I wish to do so, is that a place I often work blocks my VPN-service, but not my SSHing to my VPS...

    While I have been using Linux for a while, I'm a novice when it comes to setting-up virtual network-devices, advanced routing, and so on... so please spoonfeed me (using small words and colorful pictures ;-)

    I have been googling and looking at various answers on the StackExchange-network, but not seems to be exactly what I'm after. SSH-tunneling seemed promising, but since I don't have/know an exact domain and port for my VPN, I couldn't figure out how to use it... I guess I may need to set-up some virtual network-device on my laptop (which ends on the VPS), and connect VPN through it - but how to do this, sadly goes over my head.

  • Admin
    Admin about 8 years
    Most VPS solutions don't allow the installation of VPN services for "security reasons".
  • Shantanu Bedajna
    Shantanu Bedajna about 8 years
    sorry i didn't knew
  • Admin
    Admin about 8 years
    It's okay. I'm not down voting you, because you have a (mostly) valid answer. I was just providing one reason why this may not have been done. While most VPS solutions block this, one of the most popular cloud hosts (Amazon) does not.
  • Adam
    Adam about 6 years
    It seems that the separate --user-data-dir is required, otherwise an existing Chromium instance is used, which doesn't use the proxy.
  • BiBi
    BiBi over 4 years
    Excellent, works like a charm, thanks! For macOS, use brew install sshuttle instead of sudo apt-get install sshuttle.