Ubuntu is one of the best-known Linux distributions, distros for short, and deserves the protection that comes from using a VPN. It suffers from the same problem as any operating system, though, which is choosing a perfect VPN. But, if you’ve been following us for a while, you know we not only listed the top VPN choices for Linux, but the best Ubuntu VPN providers, specifically. Unfortunately, not all are easy to use or offer a dedicated application. We, on the other hand, think this makes the added challenge more rewarding in the end. With that, let’s get into how to add a VPN in Ubuntu.
1. Add a VPN via an app with a GUI
We’re starting with the best-case scenario. Some VPN providers, very few nowadays, offer full-fledged Ubuntu-compatible application that includes a GUI (Graphical User Interface). Two such examples we aren’t affiliated with are AirVPN and Mullvad. If that’s your case, the process is no different than using a VPN app for Windows that we demonstrated in the guide on keeping a VPN always ON. You merely need to install their app package using the following command:
sudo apt-get install vpn-app-name
Note. Replace “vpn-app-name” with the actual app package name.
2. Add a VPN in Ubuntu via Network Manager (16.04, 18.04, 20.04)
Ever since Network Manager is natively supported (as of the Ubuntu 20.04 version), VPN providers have shifted to this method. Here’s how adding a VPN via Ubuntu Network Manager works:
- In the far right corner of the top menu, click on the Network icon.
- From the drop-down menu, click on Settings.
- In the “VPN” section, click on the + icon.
Note. If you don’t see a VPN section, you’re using 18.04, 16.04, or an earlier Ubuntu version. In that case, you must open Terminal (Ctrl (Control) + Alt + T). Then, type the following command before repeating steps 1, 2, and 3:
sudo apt install network-manager-openvpn
You can also try:
sudo apt-get install network-manager-openvpn-gnome
- Now, depending on your VPN provider, you can add a VPN to Ubuntu in 3 ways:
1. OpenVPN
OpenVPN is an open-source security protocol with dedicated applications for multiple operating systems, including seldom supported ones like Ubuntu. Therefore, many VPN services opt for options, and, likely, yours does too. To use it, select OpenVPN, and then:
- Sign in to your user account and find the download link for a CA (Certificate authority) Certificate.
- Tip. Look through their Help/FAQ/Setup sections for Linux or Ubuntu. You might need to contact Customer Service too.
- Once you have it, fill out these text fields in the Add VPN window:
- Name: Anything you wish. We suggest your VPN provider’s name.
- Gateway: Enter the IP address or hostname of the VPN server such as “fr.vpn.vpn-provider.com”
- Authentication: Select/enter the following:
- Type: Password/Password with Certificates, most likely
- Username and Password: Provided by your VPN service, but not identical to your user account credentials
- CA Certificate: Upload the “.ca.crt” or “.pem” certificate file
- Click on the green Add button in the upper right corner.
- Go back a step and toggle the switch next to the VPN name you chose to On.
- From this point on, you can click on Network in the top menu > select the VPN name > Click on Connect or toggle to on.
2. Point-to-Point Tunneling Protocol (PPTP):
PPTP is no longer considered secure, so you can forget about this option. However, some VPN providers instruct you to install custom Network Manager plugins to add other protocols as an alternative. Two common examples are:
1. L2TP/IPsec
To install a NetworkManager-l2tp plugin for Ubuntu, do the following:
- Open Terminal, then enter this in succession:
sudo add-apt-repository ppa:nm-l2tp/network-manager-l2tp
sudo apt-get install network-manager-l2tp - Note. If you face any errors, type: “sudo apt-get update” before executing the second command.
- Restart your PC and you’ll see the Layer 2 Tunneling Protocol (L2TP) option.
- Enter the same information as in the OpenVPN method.
- Put a checkmark in front of “Enable IPsec tunnel to L2TP host”.
- Copy-paste the Gateway ID and Pre-shared key your VPN service provided.
- Click on OK.
2. IKEv2/IPSec
IKEv2/IPSec support was added via the custom plugin package named strongSwan. To add strongSwan to Ubuntu, proceed like this:
- Launch Terminal then type the following command:
sudo apt-get install network-manager-strongswan - Now the IKEv2 option appears on the list.
- Once again, enter the information as demonstrated in OpenVPN.
- You’ll most likely have to select Certificate/private key under “Client > Authentication”. Then, follow your VPN provider’s instructions.
2. Import from file
VPN services utilize this option when they can generate configuration files, most often for OpenVPN. After you select it, locate the “.ovpn” configuration file on your computer and double-click on it. Since the vast majority of data is auto-filled, simply enter your username and password before clicking on the Add button.
3. Use a VPN in Ubuntu via command-line app
This method is what the majority of VPN providers rely on, and is designed for older Ubuntu versions that are incompatible with Network Manager. It is also a favored solution for tech-savvy users that prefer efficiency. We’ll demonstrate the process with OpenVPN because it’s extremely likely you’ll use it too. With that said, adding VPN in Ubuntu using a command-line app works like this:
- Open Terminal.
- Enter the following command:
sudo apt-get install openvpn - Download the OpenVPN configuration file as suggested in method 2, sub-method 3.
- Get to the location of the .ovpn file in Terminal (for example, cd Downloads for “root/Downloads” folder).
Note. Some VPN services require you to get the file directly, by using:
“sudo wget https://url-to-the-config-file”
In that case, you won’t select a VPN location on the website. To get a list of all available locations, type “ls” in Terminal before pressing Enter.
- Enter this command:
sudo openvpn <openvpn configuration file name>.ovpn - If prompted for username and password, enter them.
- You’ll see an “Initialization Sequence Completed” when you’re connected. Close Terminal when you want to disconnect.
Note. This is one of many commands you can use on Ubuntu that isn’t limited to it. To help users of Linux Mint, Debian, CentOS, Fedora, and other distros, we’ll make an exhaustive guide on adding a VPN in Linux that includes more examples, and even quick access/shut down bash scripts.