Skip to content

Instantly share code, notes, and snippets.

@LeandroFranciscato
Last active August 28, 2018 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeandroFranciscato/b00348cdd69f34db85193a754c360638 to your computer and use it in GitHub Desktop.
Save LeandroFranciscato/b00348cdd69f34db85193a754c360638 to your computer and use it in GitHub Desktop.
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