How to Install and Configure OpenVPN on Debian/CentOS VPS

OpenVPN is a great open-source VPN solution that allows you to create secure connections between devices and networks over the internet. This tutorial covers how to install and configure OpenVPN on a Debian or CentOS VPS server.

Prerequisites

  • A Debian or CentOS VPS with root access
  • Command line/SSH access to the VPS

Install OpenVPN

First, update the package manager:

sudo apt update (Debian/Ubuntu)
sudo yum update (CentOS/RHEL)

Next, install OpenVPN and required dependencies:

sudo apt install openvpn easy-rsa (Debian/Ubuntu) 
sudo yum install epel-release -y && sudo yum install openvpn easy-rsa (CentOS/RHEL)

Configure the VPN Server

Generate certificates and keys:

make-cadir ~/openvpn-ca
cd ~/openvpn-ca
source vars
./clean-all
./build-ca

Generate certificate and key for the server:

./build-key-server server

Generate certificates and keys for clients:

./build-key client1
./build-key client2
(Repeat for each client)

Configure the OpenVPN service:

sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf /etc/openvpn

Edit /etc/openvpn/server.conf to point to the keys and certificates.

Finally, start OpenVPN:

sudo systemctl start openvpn@server

The VPN server should now be running on port 1194 UDP. Clients can connect using the generated .ovpn profiles.

Set Up Client Connections

Distribute the .ovpn profiles to each device/user that will connect to the VPN. Import the profile into the OpenVPN client app.

That’s it! Clients can now establish secure OpenVPN connections to your VPS server. Traffic will be encrypted and tunneled through the VPN.

Conclusion

Installing OpenVPN on a Debian/CentOS VPS provides a cost-effective way to deploy a secure VPN server. Follow this tutorial to get up and running quickly. Some additional steps like configuring firewall rules may be required for production use.

Leave a Comment