{"id":10,"date":"2026-12-03T15:34:11","date_gmt":"2026-12-03T15:34:11","guid":{"rendered":"http:\/\/localhost\/tuts.ro\/2026\/12\/03\/wireguard-your-private-network-anywhere\/"},"modified":"2026-12-05T09:44:36","modified_gmt":"2026-12-05T09:44:36","slug":"wireguard-your-private-network-anywhere","status":"publish","type":"post","link":"https:\/\/tutsplus.ro\/en\/2026\/12\/03\/wireguard-your-private-network-anywhere\/","title":{"rendered":"How to Install and Configure OpenVPN on Debian 13 Linux"},"content":{"rendered":"<p>A practical guid based on a real OpenVPN 2.6.14 installation on Debian 13 (Trixie), alongside ISPConfig, Apache, DNS and mail services. It covers certificate-based authentication, unattended startup, persistent forwarding and NAT, client profiles, troubleshooting and an optional three-session limit per certificate.<\/p>\n<h2>1. Server architecture<\/h2>\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th scope=\"col\">Parameter<\/th>\n<th scope=\"col\">Value<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>OS<\/td>\n<td>Debian 13 Trixie<\/td>\n<\/tr>\n<tr>\n<td>OpenVPN<\/td>\n<td>2.6.14 (observed installation)<\/td>\n<\/tr>\n<tr>\n<td>Authentication<\/td>\n<td>Easy-RSA certificates<\/td>\n<\/tr>\n<tr>\n<td>Protocol \/ port<\/td>\n<td>UDP 1194<\/td>\n<\/tr>\n<tr>\n<td>External interface<\/td>\n<td><code>eth0<\/code><\/td>\n<\/tr>\n<tr>\n<td>Tunnel interface<\/td>\n<td><code>tun0<\/code><\/td>\n<\/tr>\n<tr>\n<td>VPN subnet<\/td>\n<td><code>10.9.8.0\/24<\/code><\/td>\n<\/tr>\n<tr>\n<td>VPN gateway<\/td>\n<td><code>10.9.8.1<\/code> with subnet topology<\/td>\n<\/tr>\n<tr>\n<td>Firewall<\/td>\n<td>UFW, managed alongside ISPConfig<\/td>\n<\/tr>\n<tr>\n<td>Backend<\/td>\n<td>iptables-nft<\/td>\n<\/tr>\n<tr>\n<td>Optional session limit<\/td>\n<td>3 per certificate Common Name (CN)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<ol>\n<li>Windows \/ mobile \/ Cudy router<\/li>\n<li>OpenVPN server<\/li>\n<li>tun0: 10.9.8.0\/24<\/li>\n<li>UFW forwarding and NAT<\/li>\n<li>eth0<\/li>\n<li>Internet<\/li>\n<\/ol>\n<p>Run commands as root. Substitute your own server hostname, network interface and subnet as necessary. Back up existing configuration before modifying a production server, and use an SSH connection independent of the VPN.<\/p>\n<h2>2. Install OpenVPN and Easy-RSA<\/h2>\n<pre class=\"wp-block-code\"><code>apt update\napt install openvpn easy-rsa openssl python3 nmap tcpdump\nopenvpn --version\nls -l \/dev\/net\/tun<\/code><\/pre>\n<p>If the TUN device is unavailable, try <code>modprobe tun<\/code>. On a virtual server, the hosting provider may also need to enable TUN access.<\/p>\n<h2>3. Create the certificate authority and certificates<\/h2>\n<p>For a <strong>new installation only<\/strong>:<\/p>\n<pre class=\"wp-block-code\"><code>make-cadir \/etc\/openvpn\/easy-rsa\ncd \/etc\/openvpn\/easy-rsa\n.\/easyrsa init-pki\n.\/easyrsa build-ca\n.\/easyrsa build-server-full server nopass\n.\/easyrsa build-client-full vpn1\n.\/easyrsa gen-dh\n.\/easyrsa gen-crl\nopenvpn --genkey secret \/etc\/openvpn\/ta.key\nchmod 600 \/etc\/openvpn\/ta.key<\/code><\/pre>\n<p>Choose a strong CA password. Do not initialize a PKI that already contains active certificates. Keep the CA private key protected, ideally offline. For an unattended client such as a router, use <code>.\/easyrsa build-client-full vpn1 nopass<\/code> <strong>instead of<\/strong> the password-protected client creation command above. Use unique certificate names for different users or devices whenever possible.<\/p>\n<p><strong>The <code>nopass<\/code> option<\/strong> on the server key permits unattended service startup. It does not change VPN traffic encryption, but removes password encryption of the key at rest.<\/p>\n<h2>4. Directory structure<\/h2>\n<pre class=\"wp-block-code\"><code>\/etc\/openvpn\/\n\u251c\u2500\u2500 server.conf\n\u251c\u2500\u2500 ta.key\n\u251c\u2500\u2500 scripts\/\n\u2514\u2500\u2500 easy-rsa\/\n    \u251c\u2500\u2500 easyrsa\n    \u2514\u2500\u2500 pki\/\n        \u251c\u2500\u2500 ca.crt\n        \u251c\u2500\u2500 dh.pem\n        \u251c\u2500\u2500 crl.pem\n        \u251c\u2500\u2500 issued\/\n        \u2502   \u251c\u2500\u2500 server.crt\n        \u2502   \u2514\u2500\u2500 vpn1.crt\n        \u2514\u2500\u2500 private\/\n            \u251c\u2500\u2500 ca.key\n            \u251c\u2500\u2500 server.key\n            \u2514\u2500\u2500 vpn1.key<\/code><\/pre>\n<p>Protect all private keys and the shared TLS authentication key.<\/p>\n<h2>5. Configure the OpenVPN server<\/h2>\n<p>Create <code>\/etc\/openvpn\/server.conf<\/code> with the following reference configuration:<\/p>\n<pre class=\"wp-block-code\"><code>port 1194\nproto udp4\ndev tun0\ntopology subnet\n\nca \/etc\/openvpn\/easy-rsa\/pki\/ca.crt\ncert \/etc\/openvpn\/easy-rsa\/pki\/issued\/server.crt\nkey \/etc\/openvpn\/easy-rsa\/pki\/private\/server.key\ndh \/etc\/openvpn\/easy-rsa\/pki\/dh.pem\n\nverify-client-cert require\nremote-cert-tls client\ncrl-verify \/etc\/openvpn\/easy-rsa\/pki\/crl.pem\n\ntls-auth \/etc\/openvpn\/ta.key 0\ntls-version-min 1.2\n\nserver 10.9.8.0 255.255.255.0\npush \"redirect-gateway def1 bypass-dhcp\"\npush \"dhcp-option DNS 1.1.1.1\"\npush \"dhcp-option DNS 8.8.8.8\"\n\ndata-ciphers AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305\nauth SHA256\n\nkeepalive 10 60\npersist-key\npersist-tun\nmax-clients 100\n\nstatus \/var\/log\/openvpn\/openvpn-status.log 10\nstatus-version 2\nverb 3\nexplicit-exit-notify 1<\/code><\/pre>\n<pre class=\"wp-block-code\"><code>mkdir -p \/var\/log\/openvpn\nchmod 600 \/etc\/openvpn\/server.conf\nchmod 600 \/etc\/openvpn\/easy-rsa\/pki\/private\/server.key<\/code><\/pre>\n<p>This is a modern IPv4 full-tunnel example. IPv6 requires separate routing or leak-prevention measures. Older routers may need compatibility options. DNS server choices are examples, not mandatory settings.<\/p>\n<h2>6. Enable automatic startup<\/h2>\n<p>The configuration layout used in this installation is <code>\/etc\/openvpn\/server.conf<\/code> with <code>openvpn@server.service<\/code>.<\/p>\n<pre class=\"wp-block-code\"><code>systemctl enable --now openvpn@server.service\nsystemctl status openvpn@server.service\njournalctl -u openvpn@server.service -n 50 --no-pager\nss -ulnp | grep ':1194'\nip -br addr<\/code><\/pre>\n<p>Successful initialization includes <code>Initialization Sequence Completed<\/code>, a UDP socket on port 1194 and a <code>tun0<\/code> interface with address <code>10.9.8.1\/24<\/code>.<\/p>\n<p>Debian also supports <code>\/etc\/openvpn\/server\/server.conf<\/code> with <code>openvpn-server@server.service<\/code>. Do not start both instances for the same configuration.<\/p>\n<h2>7. Troubleshoot a closed port and encrypted server key<\/h2>\n<p>Nmap scans TCP by default. For UDP, run:<\/p>\n<pre class=\"wp-block-code\"><code>nmap -sU -p 1194 127.0.0.1\nss -ulnp | grep ':1194'\nsystemctl status openvpn@server.service -l --no-pager\njournalctl -u openvpn@server.service -n 100 --no-pager<\/code><\/pre>\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th scope=\"col\">Nmap result<\/th>\n<th scope=\"col\">Interpretation<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>open<\/td>\n<td>Service responded<\/td>\n<\/tr>\n<tr>\n<td>open|filtered<\/td>\n<td>No response; common for OpenVPN UDP<\/td>\n<\/tr>\n<tr>\n<td>closed<\/td>\n<td>No listener or explicit rejection<\/td>\n<\/tr>\n<tr>\n<td>filtered<\/td>\n<td>Filtering detected<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>In the actual installation, systemd reported the process as running, but no socket or TUN interface existed. The process tree revealed:<\/p>\n<pre class=\"wp-block-code\"><code>\/usr\/bin\/systemd-ask-password --icon network-vpn --timeout=0 \"Enter Private Key Password:\"<\/code><\/pre>\n<p>OpenVPN was waiting indefinitely for the encrypted private key password. The temporary solution was:<\/p>\n<pre class=\"wp-block-code\"><code>systemd-tty-ask-password-agent --query<\/code><\/pre>\n<p>For permanent unattended startup, preserve the original encrypted key and create a passwordless copy:<\/p>\n<pre class=\"wp-block-code\"><code>cp -a \/etc\/openvpn\/server.conf \/etc\/openvpn\/server.conf.bak\numask 077\nopenssl pkey \\\n  -in \/etc\/openvpn\/easy-rsa\/pki\/private\/server.key \\\n  -out \/etc\/openvpn\/easy-rsa\/pki\/private\/server-nopass.key\nchown root:root \/etc\/openvpn\/easy-rsa\/pki\/private\/server-nopass.key\nchmod 600 \/etc\/openvpn\/easy-rsa\/pki\/private\/server-nopass.key\nopenssl pkey -in \/etc\/openvpn\/easy-rsa\/pki\/private\/server-nopass.key -check -noout<\/code><\/pre>\n<p>Replace the <code>key<\/code> directive in <code>\/etc\/openvpn\/server.conf<\/code> with:<\/p>\n<pre class=\"wp-block-code\"><code>key \/etc\/openvpn\/easy-rsa\/pki\/private\/server-nopass.key<\/code><\/pre>\n<pre class=\"wp-block-code\"><code>systemctl restart openvpn@server.service\nss -ulnp | grep ':1194'<\/code><\/pre>\n<p>The server certificate and client profiles remain unchanged. The new key is unencrypted at rest; protect permissions and backups.<\/p>\n<h2>8. Enable persistent IPv4 forwarding on Debian 13<\/h2>\n<p>Debian 13 no longer automatically honors <code>\/etc\/sysctl.conf<\/code> through its standard systemd boot configuration. Use a dedicated drop-in:<\/p>\n<pre class=\"wp-block-code\"><code>printf 'net.ipv4.ip_forward = 1\\n' &gt; \/etc\/sysctl.d\/99-openvpn.conf\nsysctl --system\nsysctl net.ipv4.ip_forward\ncat \/proc\/sys\/net\/ipv4\/ip_forward<\/code><\/pre>\n<p>Expected value: <code>1<\/code>.<\/p>\n<p>If forwarding is reset, inspect conflicting settings in <code>\/etc\/sysctl.d<\/code>, <code>\/usr\/lib\/sysctl.d<\/code>, <code>\/run\/sysctl.d<\/code> and <code>\/etc\/ufw\/sysctl.conf<\/code>.<\/p>\n<h2>9. Preserve ISPConfig firewall management<\/h2>\n<p>Determine which firewall manager is active:<\/p>\n<pre class=\"wp-block-code\"><code>systemctl is-active nftables firewalld ufw netfilter-persistent\niptables --version\nufw status verbose<\/code><\/pre>\n<p>The actual installation used UFW, with iptables 1.8.11 (<code>nf_tables<\/code>). The standalone nftables, firewalld and netfilter-persistent services were inactive.<\/p>\n<p><strong>Do not enable a competing nftables service, flush the ruleset, or overwrite <code>\/etc\/nftables.conf<\/code> on this UFW-managed server.<\/strong><\/p>\n<p>Open UDP port 1194 using ISPConfig&#8217;s firewall configuration. On a standalone UFW server, the equivalent is:<\/p>\n<pre class=\"wp-block-code\"><code>ufw allow 1194\/udp<\/code><\/pre>\n<p>Back up UFW before editing:<\/p>\n<pre class=\"wp-block-code\"><code>BACKUP=\"\/root\/ufw-backup-$(date +%Y%m%d-%H%M%S)\"\nmkdir -m 700 \"$BACKUP\"\ncp -a \/etc\/ufw \"$BACKUP\/\"\ncp -a \/etc\/default\/ufw \"$BACKUP\/ufw-default\"\nnft list ruleset &gt; \"$BACKUP\/nftables-ruleset.txt\"<\/code><\/pre>\n<h2>10. Configure persistent forwarding rules<\/h2>\n<pre class=\"wp-block-code\"><code>ufw route allow in on tun0 out on eth0 from 10.9.8.0\/24 to any<\/code><\/pre>\n<p>UFW normally permits related and established return traffic automatically. Check:<\/p>\n<pre class=\"wp-block-code\"><code>grep 'ufw-before-forward.*RELATED,ESTABLISHED' \/etc\/ufw\/before.rules\ngrep DEFAULT_FORWARD_POLICY \/etc\/default\/ufw<\/code><\/pre>\n<p>Keep the existing restrictive default forwarding policy. The explicit VPN rule is preferable to allowing unrestricted forwarding.<\/p>\n<h2>11. Configure permanent NAT masquerading<\/h2>\n<p>Inspect existing NAT rules:<\/p>\n<pre class=\"wp-block-code\"><code>grep -nE '^\\*nat|^:POSTROUTING|MASQUERADE|SNAT' \/etc\/ufw\/before.rules<\/code><\/pre>\n<p>Edit <code>\/etc\/ufw\/before.rules<\/code>. If there is no existing NAT section, insert this block before <code>*filter<\/code>:<\/p>\n<pre class=\"wp-block-code\"><code># BEGIN OPENVPN NAT RULES\n*nat\n:POSTROUTING ACCEPT [0:0]\n-A POSTROUTING -s 10.9.8.0\/24 -o eth0 -j MASQUERADE\nCOMMIT\n# END OPENVPN NAT RULES<\/code><\/pre>\n<p>If a NAT section already exists, add the rule inside it before its <code>COMMIT<\/code>, ensuring the necessary chain exists. Preserve all original UFW rules.<\/p>\n<p>The original installation encountered <code>Bad argument '*filter'<\/code> because the NAT section lacked <code>COMMIT<\/code>. Each table must be committed separately. The structure must be:<\/p>\n<pre class=\"wp-block-code\"><code>*nat\n... NAT rules ...\nCOMMIT\n*filter\n... existing UFW filter rules ...\nCOMMIT<\/code><\/pre>\n<p>In <code>\/etc\/ufw\/sysctl.conf<\/code>, uncomment or add:<\/p>\n<pre class=\"wp-block-code\"><code>net\/ipv4\/ip_forward=1<\/code><\/pre>\n<p>Validate before reloading:<\/p>\n<pre class=\"wp-block-code\"><code>iptables-restore --test &lt; \/etc\/ufw\/before.rules<\/code><\/pre>\n<p>After confirming SSH access remains permitted, reload:<\/p>\n<pre class=\"wp-block-code\"><code>ufw reload\niptables -t nat -L POSTROUTING -n -v\niptables -L ufw-user-forward -n -v\nsysctl net.ipv4.ip_forward\nufw status verbose<\/code><\/pre>\n<p>Check that ISPConfig preserves the custom rules after subsequent firewall updates. If manual nftables rules were previously added, inspect them individually; do not delete complete shared tables.<\/p>\n<h2>12. Generate client profiles<\/h2>\n<p>An inline <code>.ovpn<\/code> profile contains the CA certificate, client certificate, client private key and TLS authentication key. The server and client protocol, authentication digest and TLS key direction must match.<\/p>\n<p>Create <code>\/etc\/openvpn\/generate-client.sh<\/code>:<\/p>\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\nset -euo pipefail\numask 077\n\nCLIENT=\"${1:?Usage: generate-client.sh CLIENT SERVER}\"\nSERVER=\"${2:?Specify server IP or hostname}\"\nPKI=\"\/etc\/openvpn\/easy-rsa\/pki\"\n[[ \"$CLIENT\" =~ ^[a-zA-Z0-9_-]+$ ]] || exit 1\n[[ \"$SERVER\" =~ ^[a-zA-Z0-9.-]+$ ]] || exit 1\nOUTPUT=\"\/root\/${CLIENT}.ovpn\"\n\n{\ncat &lt;&lt;PROFILE\nclient\ndev tun\nproto udp4\nremote $SERVER 1194\nresolv-retry infinite\nnobind\npersist-key\npersist-tun\nremote-cert-tls server\ndata-ciphers AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305\nauth SHA256\nkey-direction 1\nverb 3\nPROFILE\n\necho '&lt;ca&gt;'\ncat \"$PKI\/ca.crt\"\necho '&lt;\/ca&gt;'\necho '&lt;cert&gt;'\nopenssl x509 -in \"$PKI\/issued\/$CLIENT.crt\"\necho '&lt;\/cert&gt;'\necho '&lt;key&gt;'\ncat \"$PKI\/private\/$CLIENT.key\"\necho '&lt;\/key&gt;'\necho '&lt;tls-auth&gt;'\ncat \/etc\/openvpn\/ta.key\necho '&lt;\/tls-auth&gt;'\n} &gt; \"$OUTPUT\"\nchmod 600 \"$OUTPUT\"\necho \"Configuration created: $OUTPUT\"<\/code><\/pre>\n<pre class=\"wp-block-code\"><code>chmod 700 \/etc\/openvpn\/generate-client.sh\n\/etc\/openvpn\/generate-client.sh vpn1 YOUR_SERVER_IP<\/code><\/pre>\n<p>Transfer <code>\/root\/vpn1.ovpn<\/code> securely. It contains credentials and must not be published or committed to source control.<\/p>\n<h2>13. Connect from Windows<\/h2>\n<p>Install <a href=\"https:\/\/openvpn.net\/client\/\">OpenVPN Connect<\/a>, import <code>vpn1.ovpn<\/code> and connect. Verify that the client receives an address in <code>10.9.8.0\/24<\/code>, can access the Internet and uses the server&#8217;s public IPv4 address for full-tunnel traffic.<\/p>\n<h2>14. Connect from a Cudy router<\/h2>\n<p>Open the router administration interface, locate VPN client settings, choose OpenVPN and import the profile. Exact menu names depend on model and firmware.<\/p>\n<p>Older firmware may require legacy cipher compatibility. For example, if the client requires AES-128-CBC, the server can be configured with:<\/p>\n<pre class=\"wp-block-code\"><code>data-ciphers AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305:AES-128-CBC\ndata-ciphers-fallback AES-128-CBC<\/code><\/pre>\n<p>The client may also require matching cipher, digest and TLS authentication options. Only enable legacy compatibility when necessary. CBC ciphers can disable DCO acceleration.<\/p>\n<h2>15. Allow multiple simultaneous connections<\/h2>\n<p>OpenVPN normally replaces an existing connection when another session uses the same certificate CN. To permit concurrent sessions, add:<\/p>\n<pre class=\"wp-block-code\"><code>duplicate-cn<\/code><\/pre>\n<p>Remove <code>ifconfig-pool-persist<\/code> if present, because it is incompatible with <code>duplicate-cn<\/code>. The <code>max-clients<\/code> directive sets the total server limit, not a per-certificate limit.<\/p>\n<p>Prefer separate certificates for individual devices when possible, because shared certificates weaken individual revocation and accountability.<\/p>\n<h2>16. Optional: limit each certificate to three simultaneous connections<\/h2>\n<p>A custom Python\/SQLite hook can register active sessions and reject a fourth connection. Unlike a periodically updated status file, an SQLite transaction allows counting and inserting a session atomically.<\/p>\n<p>The following is the expanded reference implementation from the article, not the exact original script tested on the server. It records the remote IP and port to reduce erroneous deletion of unrelated session records. Endpoint changes and failed disconnect hooks can cause stale records, so test before production use.<\/p>\n<pre class=\"wp-block-code\"><code>mkdir -p \/etc\/openvpn\/scripts\nchmod 755 \/etc\/openvpn\/scripts\ncat &gt; \/etc\/openvpn\/scripts\/client-limit.py &lt;&lt;'PYTHON'\n#!\/usr\/bin\/python3\n\nimport os\nimport sys\nimport sqlite3\nimport ipaddress\nimport syslog\n\nMAX_CONNECTIONS = 3\nDATABASE = \"\/run\/openvpn-limit\/sessions.db\"\n\nsyslog.openlog(\"openvpn-limit\")\n\ntry:\n    action = sys.argv[1]\n    cn = os.environ.get(\"common_name\", \"\")\n    vpn_ip = os.environ.get(\"ifconfig_pool_remote_ip\", \"\")\n    remote_ip = os.environ.get(\"trusted_ip\", \"\")\n    remote_port = os.environ.get(\"trusted_port\", \"\")\n\n    if not cn or not remote_ip or not remote_port:\n        raise ValueError(\"Missing connection identity\")\n\n    vpn_ip = str(ipaddress.IPv4Address(vpn_ip))\n\n    with sqlite3.connect(DATABASE, timeout=5) as db:\n        db.execute(\"\"\"\n            CREATE TABLE IF NOT EXISTS sessions (\n                vpn_ip TEXT PRIMARY KEY,\n                common_name TEXT NOT NULL,\n                remote_ip TEXT NOT NULL,\n                remote_port TEXT NOT NULL\n            )\n        \"\"\")\n        db.execute(\"BEGIN IMMEDIATE\")\n\n        if action == \"connect\":\n            count = db.execute(\n                \"SELECT COUNT(*) FROM sessions WHERE common_name = ?\",\n                (cn,)\n            ).fetchone()[0]\n\n            if count &gt;= MAX_CONNECTIONS:\n                syslog.syslog(syslog.LOG_WARNING,\n                              f\"DENIED: {cn} - {count}\/{MAX_CONNECTIONS}\")\n                sys.exit(1)\n\n            db.execute(\"INSERT INTO sessions VALUES (?, ?, ?, ?)\",\n                       (vpn_ip, cn, remote_ip, remote_port))\n            db.commit()\n            syslog.syslog(syslog.LOG_INFO,\n                          f\"ACCEPTED: {cn} - {count + 1}\/{MAX_CONNECTIONS}\")\n\n        elif action == \"disconnect\":\n            db.execute(\n                \"DELETE FROM sessions WHERE vpn_ip = ? AND common_name = ? \"\n                \"AND remote_ip = ? AND remote_port = ?\",\n                (vpn_ip, cn, remote_ip, remote_port)\n            )\n            db.commit()\n            syslog.syslog(syslog.LOG_INFO, f\"DISCONNECTED: {cn} - {vpn_ip}\")\n        else:\n            raise ValueError(\"Invalid action\")\nexcept Exception as error:\n    syslog.syslog(syslog.LOG_ERR, str(error))\n    sys.exit(1)\n\nsys.exit(0)\nPYTHON\nchown root:root \/etc\/openvpn\/scripts\/client-limit.py\nchmod 755 \/etc\/openvpn\/scripts\/client-limit.py\npython3 -m py_compile \/etc\/openvpn\/scripts\/client-limit.py<\/code><\/pre>\n<p>Check the OpenVPN process identity:<\/p>\n<pre class=\"wp-block-code\"><code>ps -o user,group,cmd -p \"$(systemctl show -p MainPID --value openvpn@server.service)\"<\/code><\/pre>\n<p>The observed server ran as root. Create a systemd override with <code>systemctl edit openvpn@server.service<\/code>:<\/p>\n<pre class=\"wp-block-code\"><code>[Service]\nRuntimeDirectory=openvpn-limit\nRuntimeDirectoryMode=0700\nExecStartPre=\/usr\/bin\/rm -f \/run\/openvpn-limit\/sessions.db \/run\/openvpn-limit\/sessions.db-journal\nReadWritePaths=\/run\/openvpn-limit<\/code><\/pre>\n<p>This is a reference override for the root-run service. If OpenVPN drops privileges, adjust directory ownership so the actual hook user can write to it. Do not make the directory globally writable.<\/p>\n<p>Add to <code>\/etc\/openvpn\/server.conf<\/code>, integrating any existing hooks instead of blindly replacing them:<\/p>\n<pre class=\"wp-block-code\"><code>duplicate-cn\nscript-security 2\nclient-connect \"\/usr\/bin\/python3 \/etc\/openvpn\/scripts\/client-limit.py connect\"\nclient-disconnect \"\/usr\/bin\/python3 \/etc\/openvpn\/scripts\/client-limit.py disconnect\"<\/code><\/pre>\n<pre class=\"wp-block-code\"><code>systemctl daemon-reload\nsystemctl restart openvpn@server.service\njournalctl -t openvpn-limit -f<\/code><\/pre>\n<p>Test three sessions with the same certificate, then attempt a fourth. It should be rejected with <code>AUTH_FAILED<\/code>. Disconnect one admitted session and retry. Also test a different CN, abrupt disconnection, reconnects, endpoint changes and service restarts. Adjust <code>MAX_CONNECTIONS<\/code> for future connection attempts as needed.<\/p>\n<h2>17. Troubleshoot AUTH_FAILED after adding scripts<\/h2>\n<p>In the original installation the server validated the client certificate, completed TLS negotiation and allocated <code>10.9.8.2<\/code>, but then logged:<\/p>\n<pre class=\"wp-block-code\"><code>WARNING: Failed running command (--client-connect): could not execute external program\nWARNING: Failed running command (--client-disconnect): could not execute external program\nSENT CONTROL [vpn1]: 'AUTH_FAILED'<\/code><\/pre>\n<p>The connection-limiting script had been copied incompletely: its shebang, imports and initial definitions were missing. Replacing the complete script and invoking Python explicitly fixed the observed connection failure.<\/p>\n<p>Diagnostic commands:<\/p>\n<pre class=\"wp-block-code\"><code>journalctl -t openvpn-limit -n 50 --no-pager\njournalctl -u openvpn@server.service -n 80 --no-pager\nwhich python3\nhead -n 15 \/etc\/openvpn\/scripts\/client-limit.py\nnamei -l \/etc\/openvpn\/scripts\/client-limit.py\nls -ld \/run\/openvpn-limit\npython3 -m py_compile \/etc\/openvpn\/scripts\/client-limit.py\nsystemctl cat openvpn@server.service<\/code><\/pre>\n<p>If necessary, temporarily comment out <code>client-connect<\/code> and <code>client-disconnect<\/code> and restart the service to restore connectivity. The limit will be disabled until the hooks are restored. Do not regenerate valid certificates to solve a hook execution failure.<\/p>\n<h2>18. Monitor active connections<\/h2>\n<pre class=\"wp-block-code\"><code>cat \/var\/log\/openvpn\/openvpn-status.log\nwatch -n 2 cat \/var\/log\/openvpn\/openvpn-status.log\njournalctl -u openvpn@server.service -f\njournalctl -t openvpn-limit -f<\/code><\/pre>\n<p>If the optional connection limit is installed, query its database:<\/p>\n<pre class=\"wp-block-code\"><code>python3 - &lt;&lt;'PY'\nimport sqlite3\nwith sqlite3.connect(\"file:\/run\/openvpn-limit\/sessions.db?mode=ro\", uri=True) as db:\n    print(f\"{'CLIENT':25} {'CONNECTIONS':&gt;12}\")\n    print('-' * 40)\n    for cn, count in db.execute('''\n        SELECT common_name, COUNT(*) FROM sessions\n        GROUP BY common_name ORDER BY common_name\n    '''):\n        print(f\"{cn:25} {count:&gt;10}\/3\")\nPY<\/code><\/pre>\n<p>The database is created on the first hook invocation. Compare it with the OpenVPN status file to detect stale session records.<\/p>\n<h2>19. Create additional clients<\/h2>\n<pre class=\"wp-block-code\"><code>cd \/etc\/openvpn\/easy-rsa\n.\/easyrsa build-client-full vpn2\n\/etc\/openvpn\/generate-client.sh vpn2 YOUR_SERVER_IP<\/code><\/pre>\n<p>No server restart is required to admit a newly issued certificate under the existing CA.<\/p>\n<h2>20. Revoke a client certificate<\/h2>\n<pre class=\"wp-block-code\"><code>cd \/etc\/openvpn\/easy-rsa\n.\/easyrsa revoke vpn1\n.\/easyrsa gen-crl<\/code><\/pre>\n<p>Ensure the configuration contains <code>crl-verify \/etc\/openvpn\/easy-rsa\/pki\/crl.pem<\/code> and that the CRL is readable by OpenVPN. The updated CRL rejects new connections from revoked certificates. Restart the server if you need to terminate all existing sessions immediately; this disconnects other clients too. Renew the CRL before expiration.<\/p>\n<h2>21. Verify after reboot<\/h2>\n<p>During a maintenance window, perform a controlled server reboot. After reconnecting through SSH:<\/p>\n<pre class=\"wp-block-code\"><code>systemctl is-active openvpn@server.service\nsystemctl is-enabled openvpn@server.service\nsysctl net.ipv4.ip_forward\nss -ulnp | grep ':1194'\nip -br addr\niptables -t nat -L POSTROUTING -n -v\niptables -L ufw-user-forward -n -v\nufw status verbose\njournalctl -u openvpn@server.service -b -n 30 --no-pager<\/code><\/pre>\n<p>If the optional limiter is configured, also verify <code>ls -ld \/run\/openvpn-limit<\/code>.<\/p>\n<h3>Installation checklist<\/h3>\n<ul>\n<li>To verify: OpenVPN and Easy-RSA installed<\/li>\n<li>To verify: CA created and protected<\/li>\n<li>To verify: Server and client certificates generated<\/li>\n<li>To verify: Server starts without a password prompt<\/li>\n<li>To verify: Automatic startup enabled<\/li>\n<li>To verify: UDP port 1194 listening and permitted<\/li>\n<li>To verify: TUN interface initialized<\/li>\n<li>To verify: IPv4 forwarding survives reboot<\/li>\n<li>To verify: UFW forwarding and NAT persist<\/li>\n<li>To verify: ISPConfig firewall management preserved<\/li>\n<li>To verify: Windows connectivity verified<\/li>\n<li>To verify: Router connectivity verified, if applicable<\/li>\n<li>To verify: Optional three-session limit and cleanup tested<\/li>\n<li>To verify: Certificate revocation configured<\/li>\n<li>To verify: Controlled reboot tested<\/li>\n<\/ul>\n<h2>22. Common problems and solutions<\/h2>\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th scope=\"col\">Problem<\/th>\n<th scope=\"col\">Probable cause \/ solution<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Nmap reports port closed<\/td>\n<td>Check UDP scan and actual listening socket<\/td>\n<\/tr>\n<tr>\n<td>Service running but no socket<\/td>\n<td>Check for encrypted private key password prompt<\/td>\n<\/tr>\n<tr>\n<td>Connected without Internet<\/td>\n<td>Check forwarding, NAT, routes and DNS<\/td>\n<\/tr>\n<tr>\n<td>Forwarding resets after reboot<\/td>\n<td>Use <code>\/etc\/sysctl.d\/99-openvpn.conf<\/code> and verify UFW sysctl<\/td>\n<\/tr>\n<tr>\n<td><code>Bad argument '*filter'<\/code><\/td>\n<td>Missing <code>COMMIT<\/code> in preceding NAT section<\/td>\n<\/tr>\n<tr>\n<td>Router cannot connect<\/td>\n<td>Verify cipher, digest and TLS settings<\/td>\n<\/tr>\n<tr>\n<td>Existing session replaced<\/td>\n<td>Enable <code>duplicate-cn<\/code> if intentionally sharing a CN<\/td>\n<\/tr>\n<tr>\n<td><code>AUTH_FAILED<\/code> despite valid certificate<\/td>\n<td>Check server-side connection hook logs<\/td>\n<\/tr>\n<tr>\n<td>Python hook produces no logs<\/td>\n<td>Check executable, complete script, interpreter and permissions<\/td>\n<\/tr>\n<tr>\n<td>Disconnected client still occupies slot<\/td>\n<td>Check keepalive, disconnect hook and stale database records<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>For external connectivity problems, run <code>tcpdump -ni any udp port 1194<\/code> while attempting a connection. Incoming packets establish that traffic is reaching the server, but do not by themselves prove successful authentication.<\/p>\n<h2>Conclusion<\/h2>\n<p>OpenVPN can operate alongside existing production services on Debian. The real installation demonstrated the importance of unattended private key handling, Debian 13 sysctl changes, preserving ISPConfig firewall management and making NAT and forwarding rules persistent. Custom connection hooks can add per-certificate session limits, but require careful testing and monitoring.<\/p>\n<h2>Official documentation<\/h2>\n<ul>\n<li><a href=\"https:\/\/openvpn.net\/community-docs\/community-articles\/openvpn-2-6-manual\/\">OpenVPN 2.6 reference manual<\/a><\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/OpenVPN\">Debian OpenVPN Wiki<\/a><\/li>\n<li><a href=\"https:\/\/www.debian.org\/releases\/trixie\/release-notes\/issues.html\">Debian 13 release notes<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/OpenVPN\/easy-rsa\">Easy-RSA project<\/a><\/li>\n<li><a href=\"https:\/\/manpages.debian.org\/trixie\/ufw\/ufw-framework.8.en.html\">Debian UFW framework manual<\/a><\/li>\n<li><a href=\"https:\/\/openvpn.net\/client\/\">OpenVPN Connect<\/a><\/li>\n<li><a href=\"https:\/\/www.ispconfig.org\/\">ISPConfig<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Install OpenVPN on Debian 13 with certificate authentication, persistent UFW forwarding and NAT, client profiles, and practical troubleshooting.<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-10","post","type-post","status-publish","format-standard","hentry","category-networking"],"_links":{"self":[{"href":"https:\/\/tutsplus.ro\/en\/wp-json\/wp\/v2\/posts\/10","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutsplus.ro\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tutsplus.ro\/en\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/tutsplus.ro\/en\/wp-json\/wp\/v2\/comments?post=10"}],"version-history":[{"count":4,"href":"https:\/\/tutsplus.ro\/en\/wp-json\/wp\/v2\/posts\/10\/revisions"}],"predecessor-version":[{"id":36,"href":"https:\/\/tutsplus.ro\/en\/wp-json\/wp\/v2\/posts\/10\/revisions\/36"}],"wp:attachment":[{"href":"https:\/\/tutsplus.ro\/en\/wp-json\/wp\/v2\/media?parent=10"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutsplus.ro\/en\/wp-json\/wp\/v2\/categories?post=10"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutsplus.ro\/en\/wp-json\/wp\/v2\/tags?post=10"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}