How to Connect to a VPN in Ubuntu
In this article
Connecting to a VPN in Ubuntu is done through the system's network settings, where you can add a VPN profile using either the built-in OpenVPN support or a third-party client like WireGuard. The exact steps depend on which VPN protocol your provider uses, but the core process is the same: you import a configuration file or enter server details, then toggle the VPN on from the top-right menu. You'll need your VPN provider's configuration file (usually a .ovpn file for OpenVPN) and your login credentials. This guide covers both the graphical method (easiest for most users) and the command-line method for those comfortable with the terminal.
What You'll Need
- An active VPN subscription from a provider that offers OpenVPN or WireGuard configurations.
- Your VPN username and password (or a certificate/key pair if your provider uses them).
- A configuration file from your VPN provider: typically
.ovpnfor OpenVPN or.conffor WireGuard. - Internet connection (wired or Wi-Fi).
- Administrative privileges (sudo) only if you need to install additional packages.
Step-by-Step
Method 1: Using the GUI (OpenVPN)
- Open the system settings by clicking the gear icon in the top-right corner of the screen (or search for "Settings" in the Activities overview).
- In the left sidebar, scroll down and click Network.
- In the Network panel, look for the VPN section. Click the + button next to it to add a new VPN connection.
- A dialog will appear asking for the VPN type. Choose OpenVPN from the dropdown (or if your provider uses WireGuard, you may see that option—if not, see Method 2).
- In the connection name field, type a recognizable name (e.g., "My VPN").
- For the Gateway field, enter the server address your provider gave you (e.g.,
vpn.example.com). - For Authentication, choose Password (or Certificates (TLS) if your provider uses client certificates). If you have a
.ovpnfile, you can import it: click the Import from file... button and select the file—this will auto-fill most fields. - Enter your Username and Password in the appropriate fields. If your provider uses a CA certificate, click the Advanced button, go to the TLS Settings tab, and select the CA file. For most providers, leaving the default settings works.
- Click Add to save the VPN profile.
- Now, to connect, click on the network icon in the top-right corner of the screen (the Wi-Fi or network symbol). In the dropdown, you'll see your VPN listed under VPN Connections. Click it to connect.
- A dialog may ask for your password again—enter it and click Connect. Once connected, the VPN icon will appear in the top bar.
Method 2: Using WireGuard (GUI or CLI)
WireGuard is not natively supported in the default Ubuntu network settings until you install the WireGuard tools. If your provider offers WireGuard config files, do this:
- Install WireGuard by opening a terminal and running:
sudo apt install wireguard - Copy your
.conffile to/etc/wireguard/(you'll need sudo). For example:sudo cp wg0.conf /etc/wireguard/ - To connect, run:
sudo wg-quick up wg0(replacewg0with your config's name). - To disconnect, run:
sudo wg-quick down wg0 - Alternatively, you can use the Network Manager GUI: after installing WireGuard, the option to add a WireGuard VPN may appear in the VPN type dropdown. If not, you can use the command-line method above.
Method 3: Using the Terminal (OpenVPN)
- Install OpenVPN if not already present:
sudo apt install openvpn - Place your
.ovpnfile in a convenient location, e.g.,~/vpn/config.ovpn. - Connect by running:
sudo openvpn --config ~/vpn/config.ovpn - You'll be prompted for your username and password. After successful authentication, you'll see a message like
Initialization Sequence Completed. Leave the terminal open while connected. - To disconnect, press
Ctrl+Cin the terminal.
Common Mistakes
- Using the wrong protocol: Make sure you're selecting the correct VPN type (OpenVPN vs. WireGuard) that matches your config file.
- Forgetting to import the CA certificate: Some providers require a CA certificate. If you skip it, you'll get a TLS handshake error. Import the CA file in the Advanced settings.
- Entering the wrong gateway: The gateway must be the exact server hostname from your provider—typos are common.
- Not saving credentials: If you don't check "Save password" or similar, you'll be prompted every time. That's fine, but it can be annoying.
- Using sudo with GUI: The GUI VPN connection does not require sudo—only the terminal method does. Don't run the GUI with sudo.
Tips
- Always download the config file directly from your VPN provider's website or app—never from third-party sources.
- If your provider offers multiple servers, create separate VPN profiles for each server you use often.
- Test your VPN by checking your IP address on a site like ifconfig.me before and after connecting.
- For OpenVPN, you can enable the "Kill Switch" feature in your provider's app if they offer one, but the system VPN doesn't have that built-in—use a firewall rule if needed.
- If you're using the terminal method, consider using
--daemonto run OpenVPN in the background:sudo openvpn --config file.ovpn --daemon
Troubleshooting
If the VPN fails to connect, try these in order:
- Check your internet connection: Make sure you're online before attempting the VPN.
- Verify credentials: Re-enter your username and password, ensuring no extra spaces.
- Check the config file: Open the
.ovpnfile in a text editor and confirm theremoteline has the correct server address and port (usually 1194 for UDP or 443 for TCP). - Look at the logs: In the terminal method, the output will show errors. For GUI, you can run
journalctl -u NetworkManager -fin a terminal to see VPN logs. - Try a different server: Sometimes a server is down—try another from your provider.
- Check the firewall: If you have a firewall (ufw), allow the VPN port:
sudo ufw allow 1194/udp(adjust for your provider's port). - Update packages: Run
sudo apt update && sudo apt upgradeto ensure OpenVPN and network-manager are up to date. - Reinstall OpenVPN: If all else fails,
sudo apt remove openvpnthen reinstall.
Frequently Asked Questions
Does Ubuntu have a built-in VPN client?
Yes, Ubuntu's Network Manager includes OpenVPN support by default, so you can connect to OpenVPN servers without installing extra software. WireGuard requires installation.
Can I use the same VPN config file on both desktop and mobile?
Yes, most providers allow you to use the same .ovpn file on any device that supports OpenVPN, but you may need to download a separate config for mobile if your provider offers different files.
Why does my VPN disconnect after a few minutes?
This is often due to network instability or the server dropping the connection. Try using a TCP connection instead of UDP (if your provider offers it), or check your router's NAT timeout settings.
Is it safe to use a free VPN from the Ubuntu Store?
Free VPNs may log your data or show ads. It's safer to use a reputable paid VPN. If you must use a free one, read their privacy policy carefully.
Can I set up the VPN to auto-connect at startup?
Yes, in the GUI, you can edit the VPN connection settings and check "Connect automatically" under the General tab. For terminal, you can create a systemd service.
Does the VPN work with all applications?
Yes, the system-wide VPN routes all traffic through the tunnel, so all applications use it. However, some apps like torrent clients may need to be configured to use the VPN interface specifically.