Our Knowledge Base provides step-by-step guides, troubleshooting tips, and expert insights to help you manage VPS, dedicated servers, domains, DDoS protection, and more — all designed to make your experience with us fast, secure, and stress-free.
sudo apt update
sudo apt upgrade -y
sudo apt install openvpn easy-rsa -y
Create a directory for Easy-RSA:
make-cadir ~/openvpn-ca
cd ~/openvpn-ca
Edit the vars
file to customize CA settings:
nano vars
Update the following lines with your information:
set_var EASYRSA_REQ_COUNTRY "US"
set_var EASYRSA_REQ_PROVINCE "California"
set_var EASYRSA_REQ_CITY "Los Angeles"
set_var EASYRSA_REQ_ORG "MyOrganization"
set_var EASYRSA_REQ_EMAIL "admin@example.com"
set_var EASYRSA_REQ_OU "MyOrganizationalUnit"
./easyrsa init-pki
./easyrsa build-ca nopass
./easyrsa gen-req server nopass
sudo cp pki/private/server.key /etc/openvpn/
./easyrsa sign-req server server
sudo cp pki/issued/server.crt /etc/openvpn/
sudo cp pki/ca.crt /etc/openvpn/
./easyrsa gen-dh
sudo cp pki/dh.pem /etc/openvpn/
Copy the sample configuration file:
sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/
cd /etc/openvpn/
sudo gzip -d server.conf.gz
Edit the server configuration file:
sudo nano server.conf
Uncomment or set the following lines:
ca ca.crt
cert server.crt
key server.key # keep secret
dh dh.pem
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
Edit the sysctl configuration:
sudo nano /etc/sysctl.conf
Uncomment this line:
net.ipv4.ip_forward=1
Apply changes:
sudo sysctl -p
sudo systemctl start openvpn@server
sudo systemctl enable openvpn@server
sudo ufw allow 1194/udp
sudo ufw allow OpenSSH
sudo ufw enable
cd ~/openvpn-ca
./easyrsa gen-req client1 nopass
./easyrsa sign-req client client1
cp pki/private/client1.key /etc/openvpn/
cp pki/issued/client1.crt /etc/openvpn/
Create a client config file client1.ovpn
:
client
dev tun
proto udp
remote your_server_ip 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
cipher AES-256-CBC
auth SHA256
auth-nocache
verb 3
<ca>
$(cat /etc/openvpn/ca.crt)
</ca>
<cert>
$(cat /etc/openvpn/client1.crt)
</cert>
<key>
$(cat /etc/openvpn/client1.key)
</key>
Transfer the client1.ovpn file to your client machine and connect using:
openvpn --config client1.ovpn
OpenVPN is now installed and configured on your Ubuntu 20.04 server.