OpenVPN:User Management
This document covers managing OpenVPN users (clients) including adding, removing, and managing client certificates.
Overview
[edit]OpenVPN uses certificate-based authentication. Each user (client) requires:
- A unique client certificate
- A client configuration file (
.ovpn)
- Optionally, a static IP assignment via CCD file
Current Users
[edit]Client configuration files are stored in /root/:
josh.ovpn
Work_MacBook_Air.ovpn
StrawberryNAS.ovpn(Synology NAS with static IP 10.8.0.2)
Adding a New User
[edit]Method 1: Using the OpenVPN Install Script (Recommended)
[edit]If you have the openvpn-install.sh script available:
==== Run the installer script ==== bash /root/openvpn-install.sh == Select option to add a new client == == Follow the prompts to enter the client name == == The script will automatically: == == - Generate the client certificate == == - Create the .ovpn configuration file == == - Place it in /root/ ==
Method 2: Manual Certificate Creation with Easy-RSA
[edit]For manual certificate creation:
Navigate to Easy-RSA directory:
[edit]cd /etc/openvpn/server/easy-rsa/
Generate client certificate and key:
[edit]./easyrsa build-client-full clientname nopass
Replaceclientnamewith the desired client name (e.g.,newuser,laptop-john). Thenopassoption creates a certificate without a password. Remove it if you want password protection.
Create client configuration file:
[edit] You'll need to create a .ovpn file that combines:
* Client certificate
* Client private key
* CA certificate
* TLS-Crypt key
* Connection settings
Use an existing .ovpn file as a template:
cp /root/josh.ovpn /root/newclient.ovpn
Then extract and replace the certificate sections:
=== Extract client certificate from Easy-RSA === cat /etc/openvpn/server/easy-rsa/pki/issued/clientname.crt === Extract client key === cat /etc/openvpn/server/easy-rsa/pki/private/clientname.key === Replace the <cert> and <key> sections in the .ovpn file ===
Verify the configuration:
[edit]=== Test the .ovpn file syntax === openvpn --config /root/newclient.ovpn --test-crypto
Method 3: Using Easy-RSA Helper Script
[edit]Create a helper script to automate the process:
#!/bin/bash
== /root/create-openvpn-client.sh ==
CLIENT_NAME=$1
if [ -z "$CLIENT_NAME" ]; then
echo "Usage: $0 <client-name>"
exit 1
fi
cd /etc/openvpn/server/easy-rsa/
== Generate client certificate ==
./easyrsa build-client-full "$CLIENT_NAME" nopass
== Create .ovpn file ==
CLIENT_DIR="/root"
OVPN_FILE="$CLIENT_DIR/$CLIENT_NAME.ovpn"
== Start with common client configuration ==
cat > "$OVPN_FILE" << EOF
client
dev tun
proto udp
remote 87.106.61.62 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
auth SHA512
ignore-unknown-option block-outside-dns
verb 3
EOF
== Add CA certificate ==
echo "<ca>" >> "$OVPN_FILE"
cat /etc/openvpn/server/ca.crt >> "$OVPN_FILE"
echo "</ca>" >> "$OVPN_FILE"
== Add client certificate ==
echo "<cert>" >> "$OVPN_FILE"
cat "/etc/openvpn/server/easy-rsa/pki/issued/$CLIENT_NAME.crt" >> "$OVPN_FILE"
echo "</cert>" >> "$OVPN_FILE"
== Add client key ==
echo "<key>" >> "$OVPN_FILE"
cat "/etc/openvpn/server/easy-rsa/pki/private/$CLIENT_NAME.key" >> "$OVPN_FILE"
echo "</key>" >> "$OVPN_FILE"
== Add TLS-Crypt key ==
echo "<tls-crypt>" >> "$OVPN_FILE"
cat /etc/openvpn/server/tc.key >> "$OVPN_FILE"
echo "</tls-crypt>" >> "$OVPN_FILE"
echo "Client configuration created: $OVPN_FILE"
echo "Send this file securely to the client."
Make it executable:
chmod +x /root/create-openvpn-client.sh
Usage:
/root/create-openvpn-client.sh newclientname
Assigning Static IP Addresses
[edit]To assign a static IP address to a client:
Create a CCD file in /etc/openvpn/ccd/:
[edit]sudo nano /etc/openvpn/ccd/clientname
Add IP assignment:
[edit]ifconfig-push 10.8.0.X 255.255.255.0
ReplaceXwith the desired IP (e.g.,10.8.0.10).
Set proper permissions:
[edit]sudo chown nobody:nogroup /etc/openvpn/ccd/clientname sudo chmod 600 /etc/openvpn/ccd/clientname
Restart OpenVPN (if needed):
[edit]sudo systemctl restart openvpn
Example: The Synology NAS has a CCD file at /etc/openvpn/ccd/StrawberryNAS with:
ifconfig-push 10.8.0.2 255.255.255.0
Listing Active Users
[edit]To see which users are currently connected:
=== View IP persistence file (shows last assigned IPs) === cat /etc/openvpn/server/ipp.txt == Check active connections via system logs == journalctl -u openvpn | grep "Peer Connection Initiated" == Or check the VPN interface == ip addr show tun0
Revoking a User Certificate
[edit]When a user should no longer have access:
Navigate to Easy-RSA directory:
[edit]cd /etc/openvpn/server/easy-rsa/
Revoke the certificate:
[edit]./easyrsa revoke clientname
You'll be prompted to confirm. Type yes.
Update the Certificate Revocation List (CRL):
[edit]./easyrsa gen-crl
Copy the updated CRL to the server directory:
[edit]cp pki/crl.pem /etc/openvpn/server/crl.pem
Restart OpenVPN to apply the revocation:
[edit]systemctl restart openvpn
Remove client files (optional but recommended):
[edit]=== Remove .ovpn file === rm /root/clientname.ovpn === Remove CCD file if it exists === rm /etc/openvpn/ccd/clientname
Note: The revoked certificate will be immediately rejected. The user will not be able to connect even if they still have the .ovpn file.
Security Best Practices
[edit]Use descriptive client names: Use names that identify the device/user (e.g., laptop-john, phone-mary, nas-synology)
[edit]Regular certificate rotation: Renew certificates before expiration (typically annually)
[edit]Revoke unused certificates: Remove access for users who no longer need VPN access
[edit]Secure .ovpn file distribution: Use secure channels (encrypted email, secure file transfer) when sending .ovpn files to clients
[edit]Limit static IP assignments: Only assign static IPs when necessary (e.g., for services like the Synology NAS)
[edit]Monitor active connections: Regularly check who is connected and verify it's expected
[edit]Keep Easy-RSA secure: The Easy-RSA directory contains sensitive keys - restrict access:
[edit]chmod 700 /etc/openvpn/server/easy-rsa/
Backup User Certificates
[edit]Before making changes, backup user certificates:
=== Backup all certificates and keys === tar -czf openvpn-users-backup-$(date +%Y%m%d).tar.gz \ /etc/openvpn/server/easy-rsa/pki/ \ /root/*.ovpn \ /etc/openvpn/ccd/
Related Documentation
[edit]- [Server Configuration](server-configuration.md) - Server setup
- [Client Configuration](client-configuration.md) - Client setup
- [Certificate Management](certificate-management.md) - Certificate details
- Troubleshooting - User management troubleshooting