OpenVPN

1. Install OpenVPN and Easy-RSA on the VPS

Ensure your VPS has OpenVPN and Easy-RSA installed.

On Debian/Ubuntu

apt update
sudo apt install openvpn easy-rsa -y

On CentOS/RHEL

 yum install epel-release -y
sudo yum install openvpn easy-rsa -y

2. Set Up the Easy-RSA Environment

  1. Create a directory for Easy-RSA:

     codemake-cadir ~/openvpn-ca
    cd ~/openvpn-ca
  2. Initialize the Public Key Infrastructure (PKI):

    ./easyrsa init-pki
  3. Build the Certificate Authority (CA):

    ./easyrsa build-ca

    You’ll be prompted to set a password for the CA and enter a name (e.g., "VPN_CA").

  4. Generate the server certificate and key:

    ./easyrsa build-server-full server nopass
  5. Generate the Diffie-Hellman key exchange:

    ./easyrsa gen-dh
  6. Generate the HMAC key for additional security:

    openvpn --genkey --secret ta.key

3. Configure OpenVPN Server

  1. Copy the certificates and keys to the OpenVPN directory:

  2. Create the OpenVPN server configuration file:

    Add the following content to the file:

  3. Enable IP forwarding:

    Persist the setting by editing /etc/sysctl.conf:

  4. Configure firewall rules:


4. Start the OpenVPN Server

Start and enable the OpenVPN service:

Check the status:


5. Generate Client Configuration

  1. Generate a client certificate and key:

  2. Create a client configuration file:

    Add the following content to the file:


6. Transfer the Client Configuration

Transfer the client1.ovpn file to your device (PC, phone, or another client).

Example using scp:


7. Connect Using the Client

On Linux

Install OpenVPN:

On Windows

  • Download and install the OpenVPN client.

  • Import the .ovpn file and connect.

On Android/iOS

  • Download the OpenVPN Connect app.

  • Import the .ovpn file and connect.


8. Verify Connection

Check your public IP to confirm traffic is routed through the VPN:

It should display the IP address of your VPS, not your local IP.


You now have a fully functional OpenVPN server on your VPS and can connect securely from client devices!

Last updated