Jump to content

How to Install and Use a VPN on Linux Using Terminal (Step-by-Step Guide)

Featured Replies

Posted

πŸ” How to Install and Use a VPN on Linux Using Terminal (Step-by-Step Guide)

If you prefer working from the command line or you're using a minimal Linux setup without a desktop environment, you can easily set up a VPN through the terminal. In this guide, we’ll walk you through how to install and connect to a VPN using OpenVPNβ€”one of the most trusted and widely used VPN protocols on Linux.

🧰 What You Need Before You Start

To use a VPN in Linux via the terminal, make sure you have:

  • A Linux-based OS (like Ubuntu, Kali, Debian, Fedora, Arch, etc.)

  • sudo privileges

  • A .ovpn file or OpenVPN configuration details from your VPN provider

πŸ›  Step 1: Update Your System

Open your terminal and run:

sudo apt update && sudo apt upgrade -y

This ensures your package manager is up to date (For Ubuntu/Debian-based distros)

πŸ“¦ Step 2: Install OpenVPN

For Ubuntu/Debian:

sudo apt install openvpn -y

For Fedora:

sudo dnf install openvpn -y

For Arch Linux:

sudo pacman -S openvpn

πŸ“ Step 3: Get Your VPN Config File

Most VPN providers (like ProtonVPN, NordVPN, etc.) let you download a .ovpn file.

Save this file to a folder, e.g., ~/vpn/:

mkdir ~/vpnmv /path/to/your/file.ovpn ~/vpn/

πŸ”Œ Step 4: Connect to the VPN

Use OpenVPN to connect:

sudo openvpn --config ~/vpn/your-vpn-file.ovpn

You may be prompted to enter your VPN username and password depending on the provider.

πŸ”„ Optional: Background Connection (Systemd Method)

To run the VPN in the background using systemd:

  1. Copy your .ovpn file to /etc/openvpn/:

sudo cp ~/vpn/your-vpn-file.ovpn /etc/openvpn/client.conf
  1. Start the VPN:

sudo systemctl start openvpn@client
  1. Enable it on boot:

sudo systemctl enable openvpn@client
  1. To disconnect:

sudo systemctl stop openvpn@client

πŸ“Œ Check VPN Status

Check if your VPN is running:

curl ifconfig.me

It should return a different IP from your normal one.

🧠 Extra Tip

If your VPN requires DNS configuration, you can use:

sudo apt install resolvconfsudo systemctl enable resolvconfsudo systemctl start resolvconf

Then configure your DNS servers in /etc/resolv.conf.



Create an account or sign in to comment