OpenVPN
1. Install OpenVPN and Easy-RSA on the VPS
Ensure your VPS has OpenVPN and Easy-RSA installed.
On Debian/Ubuntu
Copy
apt update
sudo apt install openvpn easy-rsa -yOn CentOS/RHEL
Copy
yum install epel-release -y
sudo yum install openvpn easy-rsa -y2. Set Up the Easy-RSA Environment
Create a directory for Easy-RSA:
Copy
codemake-cadir ~/openvpn-ca cd ~/openvpn-caInitialize the Public Key Infrastructure (PKI):
Copy
./easyrsa init-pkiBuild the Certificate Authority (CA):
Copy
./easyrsa build-caYou’ll be prompted to set a password for the CA and enter a name (e.g., "VPN_CA").
Generate the server certificate and key:
Copy
./easyrsa build-server-full server nopassGenerate the Diffie-Hellman key exchange:
Copy
./easyrsa gen-dhGenerate the HMAC key for additional security:
Copy
openvpn --genkey --secret ta.key
3. Configure OpenVPN Server
Copy the certificates and keys to the OpenVPN directory:
Copy
Create the OpenVPN server configuration file:
Copy
Add the following content to the file:
Copy
Enable IP forwarding:
Copy
Persist the setting by editing
/etc/sysctl.conf:Copy
Configure firewall rules:
Copy
4. Start the OpenVPN Server
Start and enable the OpenVPN service:
Copy
Check the status:
Copy
5. Generate Client Configuration
Generate a client certificate and key:
Copy
Create a client configuration file:
Copy
Add the following content to the file:
Copy
6. Transfer the Client Configuration
Transfer the client1.ovpn file to your device (PC, phone, or another client).
Example using scp:
Copy
7. Connect Using the Client
On Linux
Install OpenVPN:
Copy
On Windows
Download and install the OpenVPN client.
Import the
.ovpnfile and connect.
On Android/iOS
Download the OpenVPN Connect app.
Import the
.ovpnfile and connect.
8. Verify Connection
Check your public IP to confirm traffic is routed through the VPN:
Copy
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