WIUNIX ACADEMY
OpenVPN MFA with client certificates and Google Authenticator
Build an isolated OpenVPN pilot with personal TOTP, PAM, exact certificate CN binding, replay controls and private recovery while retaining certificate validation.
Make this guide yoursYOUR SYSTEM. YOUR STEPS.
Where are you working?
Choose your OS and version. The prerequisites, commands and troubleshooting follow your environment.
USE YOUR OWN VALUES
Configure this tutorial
Set the example values for your environment; related explanations and copy panels update together. Never enter passwords, private keys or tokens. Values stay in this tab and are not sent to the server or share links. Check actual DNS, certificates and network policy before running commands.
Different IP addresses, domains or ports? Open the settings below, change the values and select “Apply to tutorial”, then copy the updated commands.
Set values for my environment7 editable values
THE OUTCOME
What will you have at the end?
Require a verified client certificate, matching CN/username and personal TOTP.
Supported operating systems and versions
Documentation-reviewed 2026-11-05: five DEB releases; standard RHEL/Rocky/AlmaLinux 10.2 and 9.8; dated Arch/Manjaro rolling. EPEL9 OpenVPN 2.5 needs both files without disable-dco; 2.6/2.7 disable DCO explicitly. Package names, PAM plugin discovery, nologin and SELinux differ. Historical Ubuntu fixture evidence at the end is not a fresh test of these paths.
Before you begin
- Fresh disposable systemd VM with sudo, Python 3 and iproute tools already available for preflight, independent console, existing DNS/firewall ownership and unused 10.93.0.0/24 pool; no installed VPN.
- Controlled CA, individual client certificate, current CRL, protected transfer and personal TOTP app.
- Open settings, edit, Apply, then copy. Public values stay only in this tab/language/article/environment; never enter seeds, codes, passwords or keys.
Require a certificate AND a personal TOTP
Build a separate pilot OpenVPN instance on a fresh VM. A client must possess a valid certificate/private key, submit its exact certificate CN as username, and enter a personal TOTP in the password box. The PAM stack below validates the OTP alone; it does not ask for a Linux password. The certificate key and authenticator must be held separately: storing both on one compromised laptop weakens factor independence.
Allow about 80 minutes for this intermediate pilot, plus PKI issuance and private enrollment. It does not replace an organization’s access design. TOTP is phishable; authentication neither authorizes every tunnel destination nor protects a stolen connected session.
MFA terminology boundary: a software certificate key and a TOTP without independently enforced activation can both be possession-based. This pilot alone does not demonstrate NIST AAL2 or two different factor categories. If policy requires that assurance, enforce and assess a knowledge/biometric activation factor for the key or authenticator rather than inferring it from two prompts.
Keep certificate identity through both checks
vpn.example.net reaches 192.0.2.40 on UDP 11940, directly or through an explicitly reviewed NAT rule. Certificate validation happens before PAM. The packaged auth-pam plugin checks the named user’s seed; a second authentication hook compares that username with the original certificate CN. Both must succeed. username-as-common-name is deliberately absent: it changes names seen by later hooks and CCD lookup, and is not a CN/username equality check.
The fixed pilot address pool is 10.93.0.0/24, server 10.93.0.1. It must not overlap any client, VM or routed network. No default route, DNS push, forwarding, NAT or client-to-client access is configured. The initial test reaches only an approved service on the VPN server.
LET’S BUILD
Check a fresh VM, time and collisions
Use an independent console and a fresh sudo-capable VM, never paste these creation steps over an existing VPN. Confirm 192.0.2.40 is assigned locally and UDP 11940 is unused. The hostname must resolve to the public ingress, which may differ from this local address. Stop for an existing account academyvpn, interface tun-mfa, directory /srv/academy-openvpn-mfa, PAM service or unit academy-mfa. Review parent directories for symlinks before proceeding.
The time synchronization result must be yes and the phone must use automatic accurate time. Keep the existing NTP provider; repair it through its owner rather than installing a second daemon. Do not change host time to test an OTP. Apply only the pilot UDP rule and restricted tunnel INPUT access through the firewall owner; never flush or replace a firewall.
Dedicated pilot VM; private terminal for enrollment
(
set -euo pipefail
cat /etc/os-release
test "$(ps -p 1 -o comm=)" = systemd
ip -br address
ip route show table all
sudo ss -lunp
sudo python3 - <<'PY'
import json,subprocess,pwd,grp,os
for name in ('academyvpn','academy-openvpn'):
for lookup in (pwd.getpwnam,grp.getgrnam):
try: lookup(name)
except KeyError: pass
else: raise SystemExit('Existing account/group: '+name)
for path in ('/srv/academy-openvpn-mfa','/etc/openvpn','/etc/pam.d/academy-mfa','/etc/systemd/system/academy-mfa.service'):
if os.path.lexists(path): raise SystemExit('Existing path: '+path)
states=subprocess.check_output(['systemctl','list-unit-files','--no-legend','--no-pager'],text=True)
if any(line.split()[0]=='academy-mfa.service' for line in states.splitlines() if line.split()):
raise SystemExit('Existing or masked pilot unit')
addresses=json.loads(subprocess.check_output(['ip','-j','-4','address'],text=True))
if not any(info.get('local')=='192.0.2.40' for item in addresses for info in item.get('addr_info',[])):
raise SystemExit('Listener IP is not locally assigned')
links=json.loads(subprocess.check_output(['ip','-j','link'],text=True))
if any(item.get('ifname')=='tun-mfa' for item in links): raise SystemExit('TUN name collision')
if subprocess.check_output(['timedatectl','show','-p','NTPSynchronized','--value'],text=True).strip()!='yes':
raise SystemExit('Repair existing time synchronization first')
print('Fresh identity/path, local IP and synchronized time: OK')
PY
timedatectl status
)No collision; the local ingress, non-overlapping pool, independent console and synchronized time are confirmed.
LET’S BUILD
Install signed packages for the selected release
Use signed distribution packages: apt on DEB; official base repositories plus Fedora EPEL on RPM; a full synchronized update from its own repositories on Arch/Manjaro. Review the transaction on these disposable VMs; do not install/upgrade this stack during an incident.
This covers OpenVPN 2.5, 2.6 and 2.7 with a real difference: EPEL9’s 2.5 lacks DCO and rejects disable-dco, so the 9.x selection omits that line on both server and client. Record actual versions and vendor security backports. Historical Ubuntu fixture tests do not establish fresh VM coverage.
Dedicated pilot VM; private terminal for enrollment
(
set -euo pipefail
. /etc/os-release
test "$ID" = "almalinux"
test "$VERSION_ID" = "10.2"
sudo dnf install dnf-plugins-core
sudo dnf config-manager --set-enabled crb
sudo dnf install epel-release
sudo dnf repolist --enabled
sudo dnf info openvpn google-authenticator
sudo dnf install openvpn google-authenticator python3 openssl ca-certificates nano shadow-utils iproute policycoreutils-python-utils audit
rpm -q openvpn google-authenticator selinux-policy-targeted
sudo /usr/sbin/openvpn --version
)The release guard passes and actual signed package versions are recorded.
LET’S BUILD
Create a dedicated account and discover the plugin
Create a fresh tree, one personal enrollment identity and a separate locked non-login academy-openvpn account for the reduced daemon. Neither account/group may already exist; root-owned, non-symlink parents must not be writable by other accounts. The personal identity has no shell/sudo, and the daemon alone gets its private temporary credential directory.
Discover the auth-pam library from the selected package manager’s file list and resolve it to one real root-owned non-writable file. The privileged PAM helper updates personal replay/rate-limit state after daemon UID reduction. Do not add chroot or replace the plugin to evade failures. Inspect partial state; never rerun creation blindly.
Dedicated pilot VM; private terminal for enrollment
sudo python3 - <<'PY'
import os,stat,pathlib,pwd,grp,subprocess
r=pathlib.Path('/srv/academy-openvpn-mfa')
if not r.is_absolute() or str(r) in ('/','/srv','/opt','/etc','/tmp','/var'):
raise SystemExit('Choose a fresh dedicated child directory')
for parent in reversed(r.parents):
m=parent.lstat()
if not stat.S_ISDIR(m.st_mode) or m.st_uid!=0 or m.st_mode & 0o022:
raise SystemExit('Unsafe parent: '+str(parent))
if os.path.lexists(r): raise SystemExit('Existing lab root')
for path in ['/etc/pam.d/academy-mfa','/etc/systemd/system/academy-mfa.service']:
if os.path.lexists(path): raise SystemExit('Existing pilot service')
for name in ('academyvpn','academy-openvpn'):
for lookup in (pwd.getpwnam,grp.getgrnam):
try: lookup(name)
except KeyError: pass
else: raise SystemExit('Existing user/group: '+name)
if 'academyvpn' == 'academy-openvpn': raise SystemExit('Choose a different personal username')
r.mkdir(mode=0o755);os.chmod(r,0o755)
for name,mode in [('pki',0o700),('users',0o755),('auth-tmp',0o700)]:
(r/name).mkdir(mode=mode);os.chmod(r/name,mode)
subprocess.run(['useradd','--system','--user-group','--no-create-home','--home-dir','/nonexistent','--shell','/usr/sbin/nologin','academy-openvpn'],check=True)
subprocess.run(['useradd','--system','--user-group','--home-dir',str(r/'users/academyvpn'),'--create-home','--shell','/usr/sbin/nologin','academyvpn'],check=True)
u=pwd.getpwnam('academyvpn');os.chmod(r/'users/academyvpn',0o700);os.chown(r/'users/academyvpn',u.pw_uid,u.pw_gid)
n=pwd.getpwnam('academy-openvpn');os.chown(r/'auth-tmp',n.pw_uid,n.pw_gid)
paths=[x for x in subprocess.check_output(['rpm','-ql','openvpn'],text=True).splitlines() if x.endswith('/openvpn-plugin-auth-pam.so') and pathlib.Path(x).is_file()]
targets={pathlib.Path(x).resolve() for x in paths}
if len(targets)!=1: raise SystemExit('Ambiguous/missing package plugin')
plugin=next(iter(targets));m=plugin.stat()
if m.st_uid!=0 or m.st_mode & 0o022: raise SystemExit('Unsafe plugin owner/mode')
(r/'auth-pam.so').symlink_to(plugin)
print('Fresh pilot tree, personal identity, daemon identity and packaged plugin:',plugin)
PYA new locked identity, private home,0700 auth temporary directory and validated package-plugin link exist.
LET’S BUILD
Enroll privately, once per person
Run only in a private unrecorded terminal attended by the actual user. The command is interactive and intentionally reveals a QR/seed and recovery codes: never run it through this page, screen sharing, saved command output or a logging automation. Check that the home has no existing seed, then enroll Google Authenticator or another compatible TOTP app. Choose time-based tokens, disallow reuse, a small three-code window and three attempts per30seconds. The flags set those choices; confirm saving the file after comparing the app.
Do not follow an enrollment URL that sends the seed to an external QR service. Keep emergency codes offline and private, separate from the certificate and phone. Never put a seed, QR, OTP or recovery code in reader configuration, source JSON, screenshots or support logs. One identity gets one unique seed; administrators must not distribute a shared seed.
Dedicated pilot VM; private terminal for enrollment
set -eu
sudo test ! -e '/srv/academy-openvpn-mfa/users/academyvpn/.google_authenticator'
sudo test ! -L '/srv/academy-openvpn-mfa/users/academyvpn/.google_authenticator'
sudo -H -u 'academyvpn' google-authenticator -t -d -w 3 -r 3 -R 30
sudo chmod 0600 '/srv/academy-openvpn-mfa/users/academyvpn/.google_authenticator'
sudo stat -c '%U %a %n' '/srv/academy-openvpn-mfa/users/academyvpn/.google_authenticator'
Private enrollment completes with a user-owned0600 seed; no seed/code is copied into public evidence.