On this page
Why choose OpenVPN over WireGuard?
OpenVPN is worth the extra setup when you need TCP transport or per-user certificates you can revoke. It can listen on TCP 443, which passes networks that drop unknown UDP, and its X.509 model lets you expire or revoke one person without touching anyone else. For raw speed and simplicity, a WireGuard server usually wins. This guide covers Ubuntu 24.04 and 22.04 plus Debian 12 and 13, where the packaged OpenVPN 2.6 and easy-rsa 3 are current. Prepare a sudo user as in the first SSH session tutorial.
How do you install OpenVPN and easy-rsa?
Both packages are in the standard repositories:
sudo apt update
sudo apt install -y openvpn easy-rsa
openvpn --version | head -1
ls /usr/share/easy-rsaKeep the certificate authority in your own home folder, not inside /etc/openvpn, so the CA key never sits next to the running service. The Debian helper make-cadir creates a fresh working copy:
make-cadir ~/openvpn-ca
cd ~/openvpn-ca
chmod 700 ~/openvpn-caHow do you build the PKI?
Initialise the PKI, create the CA, then a server key pair signed by that CA. Elliptic curve keys keep handshakes fast; set that in vars first:
cat >> vars <<'EOF'
set_var EASYRSA_ALGO ec
set_var EASYRSA_CURVE secp384r1
set_var EASYRSA_CERT_EXPIRE 825
EOF
./easyrsa init-pki
./easyrsa build-ca nopass
./easyrsa gen-req server nopass
./easyrsa sign-req server serverEach command asks you to confirm or enter a common name; type yes when signing. Leaving out nopass on build-ca protects the CA key with a passphrase, which is wise if more than one admin has shell access. Next create the shared key used by tls-crypt, which hides and authenticates the handshake, and copy the server files into place:
sudo openvpn --genkey secret /etc/openvpn/server/tc.key
sudo cp pki/ca.crt pki/issued/server.crt pki/private/server.key /etc/openvpn/server/
sudo chmod 600 /etc/openvpn/server/server.key /etc/openvpn/server/tc.keyNo Diffie-Hellman file is needed: with dh none the server uses elliptic curve key exchange.
What goes in server.conf?
Create /etc/openvpn/server/server.conf:
port 1194
proto udp
dev tun
ca ca.crt
cert server.crt
key server.key
dh none
tls-crypt tc.key
tls-version-min 1.2
data-ciphers AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305
topology subnet
server 10.9.0.0 255.255.255.0
server-ipv6 fd42:9:9::/64
push "redirect-gateway def1 ipv6 bypass-dhcp"
push "dhcp-option DNS 9.9.9.9"
keepalive 10 60
user nobody
group nogroup
persist-key
persist-tun
verb 3
explicit-exit-notify 1The redirect-gateway push sends all client IPv4 and IPv6 traffic through the tunnel. For TCP 443 instead, change the first two lines to port 443 and proto tcp, and drop explicit-exit-notify, which only applies to UDP.
How do you set up forwarding, NAT and the firewall?
Turn on forwarding, then masquerade the tunnel ranges out of the public interface (shown by ip route show default, here eth0):
printf 'net.ipv4.ip_forward = 1\nnet.ipv6.conf.all.forwarding = 1\nnet.ipv6.conf.eth0.accept_ra = 2\n' | sudo tee /etc/sysctl.d/99-openvpn.conf
sudo sysctl --systemWith ufw, add the NAT rules at the top of /etc/ufw/before.rules and /etc/ufw/before6.rules, above the *filter line. For IPv4:
*nat
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -s 10.9.0.0/24 -o eth0 -j MASQUERADE
COMMITUse the same block in before6.rules with -s fd42:9:9::/64. Then allow the port and routed traffic:
sudo ufw allow 1194/udp
sudo ufw route allow in on tun0 out on eth0
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw reloadThe firewall rules tutorial covers plain nftables if you do not use ufw.
How do you start the server?
The openvpn-server@ unit reads /etc/openvpn/server/NAME.conf:
sudo systemctl enable --now openvpn-server@server
systemctl status openvpn-server@server --no-pager
ip addr show tun0
ss -ulpn | grep 1194The log line Initialization Sequence Completed in journalctl -u openvpn-server@server means the server is ready.
How do you create a client profile?
Sign a client certificate, then bundle everything into one .ovpn file that any OpenVPN app imports. In the CA folder:
cd ~/openvpn-ca
./easyrsa gen-req laptop nopass
./easyrsa sign-req client laptopSave this helper as ~/make-ovpn.sh and run bash ~/make-ovpn.sh laptop:
#!/bin/bash
set -e
N="$1"; CA=~/openvpn-ca/pki
{
cat <<EOF
client
dev tun
proto udp
remote 198.51.100.24 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
data-ciphers AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305
verb 3
EOF
echo "<ca>"; cat "$CA/ca.crt"; echo "</ca>"
echo "<cert>"; openssl x509 -in "$CA/issued/$N.crt"; echo "</cert>"
echo "<key>"; cat "$CA/private/$N.key"; echo "</key>"
echo "<tls-crypt>"; sudo cat /etc/openvpn/server/tc.key; echo "</tls-crypt>"
} > ~/"$N.ovpn"
chmod 600 ~/"$N.ovpn"Copy laptop.ovpn to the device over SFTP and import it. The file contains a private key, so never send it through chat or plain email.
How do you revoke a user and keep things maintained?
Revocation adds the certificate to a list the server checks on every connection:
cd ~/openvpn-ca
./easyrsa revoke laptop
./easyrsa gen-crl
sudo cp pki/crl.pem /etc/openvpn/server/crl.pem
sudo chmod 644 /etc/openvpn/server/crl.pem
echo 'crl-verify crl.pem' | sudo tee -a /etc/openvpn/server/server.conf
sudo systemctl restart openvpn-server@serverThe CRL itself expires (180 days by default), so regenerate and copy it on a schedule, for example with a monthly cron job. Package updates arrive through sudo apt upgrade; restart the unit afterwards. If clients connect but cannot browse, recheck the NAT block and sysctl net.ipv4.ip_forward; if they never connect, a mismatched tls-crypt key or a closed port is the usual cause, and the server journal names which.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about OpenVPN server with easy-rsa
Where is the OpenVPN log?
In the systemd journal: journalctl -u openvpn-server@server -f follows it live. Raise verb to 4 or 5 while debugging and set it back afterwards.
Should I keep the CA on the VPN server?
It works, but it is safer to move ~/openvpn-ca to an offline machine once the server and first clients are signed. Anyone with the CA key can issue valid client certificates.
Can OpenVPN and WireGuard run on the same server?
Yes. They use different ports and interfaces (tun0 and wg0); give each its own tunnel range and NAT rule.
How do I give a user a fixed tunnel address?
Add client-config-dir ccd to server.conf and create /etc/openvpn/server/ccd/laptop containing ifconfig-push 10.9.0.50 255.255.255.0; the file name must match the certificate common name.
Is the OpenVPN image different from this manual setup?
The OpenVPN image is Ubuntu 24.04 with OpenVPN preinstalled and ready to accept client profiles, which saves the PKI and configuration steps on this page. Build it by hand when you need Debian or custom certificate policies.
How large a plan does OpenVPN need?
OpenVPN encrypts on one CPU thread per process, so a faster core helps more than more cores. F1-2 on the High Frequency line is a sensible start for a few users.
More in VPN and private DNS
- WireGuard VPN server (manual setup)
- wg-easy WireGuard web UI
- WGDashboard for WireGuard
- Pritunl VPN server
- OpenConnect VPN server (ocserv)
- AdGuard Home DNS filter
- Pi-hole DNS sinkhole
- Unbound validating resolver
- Technitium DNS Server
- IPsec VPN with strongSwan
- Squid forward proxy with authentication
- Shadowsocks proxy server
- Authoritative DNS with BIND 9