Installing and configuring a VPN on Linux via command line is not a tough task at all. With a few easy steps you can be rockin, and rollin ready to take on the world.
Update && Install
First step we want to make sure the latest and greatest version of software, and packages gets installed. Issue the following command to update, and upgrade the currently installed packages, and install the OpenVPN linux package. Depending on how long it has been since you’ve done updates this should take no longer than a minute.
sudo apt update && sudo apt upgrade && sudo apt install openvpn unzip -y
After updates and installation you should now be able to navigate to your OpenVPN directory using
In this tutorial I’m using my VPN providers configuration files. If you don’t have one I suggest you taking a look at PIA to further protect yourself!
To grab our VPN files we’ll use ‘wget’ to download them from the internet directly into our OpenVPN directory. Don’t forget to move into the OpenVPN directory
cd /etc/openvpn/ before next command! To download the config files issue the folllwing command:
sudo wget https://www.privateinternetaccess.com/openvpn/openvpn.zip
Now that these are downloaded into our openvpn directory extract them ‘unzip’. The following command will extract them, and delete the old zip file.
sudo unzip openvpn.zip && sudo rm openvpn.zip
Connecting to VPN
Now that we have our files extracted our openvpn directory should look somewhat like below.
To connect to our preferred location we can simply connect using the following command:
sudo openvpn --config "YOURVPNCONNECTION.ovpn"
You may now be prompted with your local machine sudo passoword, and then your VPN username/password. It is important to replace the filler portion with your actual VPN name. Also, we must not forget that since we are inside
/etc/openvpn/ you must include
sudo or else your attempt at connecting to the VPN will fail.
You will know your connection has been sucessfully established when you see the following:
To disconnect from your VPN hit
ctrl+c and now your session has been disconnected.
Background the Process (optional)
In the video tutorial towards the end we mentioned a way to background the vpn connection just incase you’re limited in terminals, or just running a headless box. You will need to install an extra package that I did not mention in the beginning of this guide called ‘screen’. To install this package issue the following command:
sudo apt install screen
Think of screen as a “virtual terminal” on top of your host terminal. Once you’ve got that in your mind let’s get ready to rock. Throw the command
screen by itself and you should see a similar message.
sudo screen -r [your session]
Hitting tab after the
-r will autofill your last screen session. To kill your current screen session simply type exit to now kill your screen session.