There are two main types of VPN connections supported by linux, PPTP and OpenVPN. For simplicity we're going to focus on OpenVPN. This tutorial assumes that you have a VPN service that provided you with a config file, and either a username and password, a CA certificate, or both.

I personally use privateinternetaccess.com ($6.95/month), but there are some free ones available (vpnbook.com for example) that you can use for this tutorial if you don't want to sign up for a paid VPN right away.

Install OpenVPN:

sudo apt-get update sudo apt-get install openvpn

Create a script to kick off your vpn connection and make it executable:

cd ~/ touch vpn.sh chmod +x vpn.sh

Now edit your vpn.sh script to look like this:

#!/bin/sh sudo openvpn --config /path/to/your/openvpn/config/file --script-security 2

Now you should be able to execute this script to connect to your vpn:

./vpn.sh

It will most likely prompt you for your username and password, and then you will be connected to the VPN and all of your traffic should tunnel through there.

How do I know I'm connected to the VPN? - An easy way to check that you are connected to your VPN is to point your browser athttps://duckduckgo.com/?q=ip before and after you connect to your VPN. This pag will show you what your current ip address is, and it should be different when you are connected to the VPN than it is when you are not.

You can also check your ip address from the command line using this command:

curl ifconfig.me/ip

How do I keep the VPN connected when I log out? - You can use a program called - You can use a program called GNU Screen to keep programs running after you close out of terminal or disconnect from an SSH connection to your server. You can install GNU Screen by running:

sudo apt-get update sudo apt-get install screen

And just type "screen" to start a screen session. From within a screen session you can run your vpn.sh script, and then press "Ctrl+a d" (press Ctrl+a and then press the d key) to disconnect from your screen session while leaving it running in the background. To reconnect to your screen session later just run: