Setting up OpenVPN from the Linux CLI is a little more tricky than using a GUI, but it’s a great option for servers or if you prefer the command line. In this guide, I’ll walk you through setting up Private Internet Access (PIA) VPN using OpenVPN on your Linux machine.

Step 1: Install OpenVPN

Before you can connect to PIA’s VPN servers, you need to have OpenVPN installed on your host. Open your terminal and run the following command:

sudo apt-get install openvpn

Step 2: Navigate to OpenVPN Configuration Directory

Now that OpenVPN is installed, you need to change to the directory where configuration files are stored. Let’s go to the OpenVPN folder:

cd /etc/openvpn

Step 3: Download PIA OpenVPN Config Files

PIA provides a set of OpenVPN configuration files that you can use to connect to their servers. Download the config files using this command:

sudo wget https://www.privateinternetaccess.com/openvpn/openvpn.zip

Step 4: Unzip the Config Files

Now, let’s extract the configuration files from the zip archive into the current directory:

sudo unzip openvpn.zip

Step 5: Copy the Desired Server Config

PIA has servers in different locations, so you’ll need to select the one that works best for you. For example, if you want to use a Netherlands-based server, copy the configuration file for that server and rename it (Follow the naming convention pia-<location>.conf):

sudo cp netherlands.ovpn pia-nl.conf

Step 6: Edit the Configuration File

Next, let’s edit the configuration file to make sure it’s set up for authentication. Open the file with your preferred text editor:

sudo vim pia-nl.conf

Inside this file, look for the line that says auth-user-pass. Change it to:

auth-user-pass login.conf

This tells OpenVPN to reference a separate file (login.conf) for your PIA username and password.

Step 7: Create the login.conf File

Now, let’s create the login.conf file that will store your PIA login credentials. Open it with:

sudo vim login.conf

Inside this file, add your PIA username and password like this (there will be nothing else in this file):

yourPIAusername
yourPIApassword

Step 8: Secure the login.conf File

Let’s update the permissions on the credentials file to lock it down a bit:

sudo chmod 400 login.conf

Step 9: Auto-Start OpenVPN on Boot

Now that everything is configured, you probably want the VPN to start automatically when your host boots up. To do this, we need to modify OpenVPN’s default settings. Open the configuration file:

sudo vim /etc/default/openvpn

Add this line to ensure the Netherlands server connects automatically on boot (replace pia-nl with the name of your configuration file):

AUTOSTART="pia-nl"

This ensures OpenVPN uses the pia-nl.conf configuration file at startup.

Step 10: Reboot Your Host

With everything set up, it’s time to reboot your host to apply the changes:

sudo reboot -r now

Step 11: Verify Your IP Address

After rebooting, check to see if your IP address has changed and that the VPN is active. You can verify your IP address with:

curl -s https://icanhazip.com/ | xargs -I {} curl -s https://ipinfo.io/{}

If the VPN is working correctly, this command should show information about the server you connected to (in this case, the Netherlands).

Step 12: Check OpenVPN Service Status

Finally, you can confirm that the OpenVPN service is running correctly by checking its status:

systemctl status openvpn@pia-nl

Wrapping Up

That’s it. Private Internet Access (PIA) VPN is now set up on your Linux system using OpenVPN via the CLI. By following these steps, your internet traffic is securely routed through PIA’s VPN servers. You can explore additional server locations by copying different .ovpn files and adjusting the configuration as needed. Now what happens if the VPN disconnects? I’ll leave that to you to figure out. Happy routing! 🙂