Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Making a vpn using ssh tunnel

On Server Side

First edit "/etc/ssh/sshd_config"

PermitTunnel yes 
PermitRootLogin = yes

Restart server

sudo service ssh restart

On Client Side

If there isn't a interface in server side yet

Add a network interface on server side

sudo ssh -f -o Tunnel=ethernet -w 0:0 root@ServerIP ifconfig tap0 10.5.5.1 netmask 255.255.255.0

Add a network interface on client side (it sometimes doesn't work, but it works anyway)

sudo ifconfig tap0 10.5.5.2 netmask 255.255.255.0 up

After you've set up the interface on server side...

Access server seeting up the port

sudo ssh -f -N -T -R 22222:localhost:22 ServerIP

Sometimes it's necessary to configure the /etc/ssh/sshd_config in the client-side, to allow Tunel and root login.

On Server Side (Again)

Access the client using the port you've set up before

ssh -p 22222 root@localhost

If you're going to be accessing this host on a regular basis, you can also simplify access by adding a few lines to your ~/.ssh/config file:

host anyhost
    User root
    Hostname localhost
    Port 22222

Then you can access the client like this:

ssh root@anyhost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.