Configure OpenVPN LDAP authentication and user management with Active Directory integration

Advanced 45 min Apr 17, 2026 171 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Set up OpenVPN with LDAP authentication to integrate with Active Directory for centralized user management. Configure group-based access control and combine certificate-based authentication with LDAP for enterprise security.

Prerequisites

  • Active Directory domain controller
  • OpenVPN server with root access
  • Valid SSL certificates for LDAP
  • Network connectivity to domain controller

What this solves

This tutorial configures OpenVPN to authenticate users against Active Directory using LDAP, eliminating the need to manage individual certificate files for each user. You'll set up group-based access control where AD groups determine VPN access permissions, and combine certificate-based authentication with LDAP credentials for enhanced security.

Step-by-step configuration

Install OpenVPN and LDAP plugin

Install OpenVPN server and the LDAP authentication plugin that enables Active Directory integration.

sudo apt update
sudo apt install -y openvpn easy-rsa openvpn-auth-ldap
sudo dnf update -y
sudo dnf install -y epel-release
sudo dnf install -y openvpn easy-rsa openvpn-auth-ldap

Set up certificate authority and server certificates

Create the PKI infrastructure for OpenVPN. Even with LDAP authentication, you still need server certificates for TLS encryption.

sudo mkdir -p /etc/openvpn/easy-rsa
sudo cp -r /usr/share/easy-rsa/* /etc/openvpn/easy-rsa/
cd /etc/openvpn/easy-rsa

Initialize the PKI and create the certificate authority:

sudo ./easyrsa init-pki
sudo ./easyrsa build-ca nopass

Generate server certificate and Diffie-Hellman parameters:

sudo ./easyrsa gen-req server nopass
sudo ./easyrsa sign-req server server
sudo ./easyrsa gen-dh
sudo openvpn --genkey secret /etc/openvpn/ta.key

Copy certificates to OpenVPN directory

Move the generated certificates to the OpenVPN configuration directory with correct permissions.

sudo cp /etc/openvpn/easy-rsa/pki/ca.crt /etc/openvpn/
sudo cp /etc/openvpn/easy-rsa/pki/issued/server.crt /etc/openvpn/
sudo cp /etc/openvpn/easy-rsa/pki/private/server.key /etc/openvpn/
sudo cp /etc/openvpn/easy-rsa/pki/dh.pem /etc/openvpn/dh2048.pem

Set secure permissions on the private key:

sudo chmod 600 /etc/openvpn/server.key
sudo chown root:root /etc/openvpn/server.key

Configure LDAP authentication plugin

Create the LDAP authentication configuration file that defines how OpenVPN connects to Active Directory.

<LDAP>
    URL             ldaps://dc1.example.com:636
    BindDN          "CN=openvpn-service,OU=Service Accounts,DC=example,DC=com"
    BindPW          "your-service-account-password"
    Timeout         15
    TLSEnable       yes
    TLSCACertFile   /etc/ssl/certs/ca-certificates.crt
    TLSCertFile     /etc/openvpn/ldap-client.crt
    TLSKeyFile      /etc/openvpn/ldap-client.key
    FollowReferrals yes
</LDAP>

<Authorization>
    BaseDN          "OU=Users,DC=example,DC=com"
    SearchFilter    "(&(sAMAccountName=%u)(memberOf=CN=VPN-Users,OU=Groups,DC=example,DC=com))"
    RequireGroup    true
    
    <Group>
        BaseDN      "OU=Groups,DC=example,DC=com"
        SearchFilter "(&(objectClass=group)(member=%D))"
        MemberAttribute member
    </Group>
</Authorization>

Create OpenVPN server configuration

Configure OpenVPN server with LDAP authentication and certificate-based encryption. This combines both authentication methods.

port 1194
proto udp
dev tun

ca /etc/openvpn/ca.crt
cert /etc/openvpn/server.crt
key /etc/openvpn/server.key
dh /etc/openvpn/dh2048.pem
tls-auth /etc/openvpn/ta.key 0

Network configuration

server 10.8.0.0 255.255.255.0 push "redirect-gateway def1 bypass-dhcp" push "dhcp-option DNS 8.8.8.8" push "dhcp-option DNS 8.8.4.4"

LDAP Authentication

plugin /usr/lib/openvpn/openvpn-auth-ldap.so /etc/openvpn/auth-ldap.conf client-cert-not-required username-as-common-name

Security settings

cipher AES-256-GCM auth SHA256 tls-version-min 1.2 tls-cipher TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384

Connection settings

keepalive 10 120 comp-lzo user nobody group nogroup persist-key persist-tun

Logging

status /var/log/openvpn-status.log log-append /var/log/openvpn.log verb 4 mute 20

Client management

max-clients 50 duplicate-cn

Configure Active Directory service account

Create a dedicated service account in Active Directory for OpenVPN LDAP binds. This account needs minimal privileges.

Note: Perform these steps on your Windows Domain Controller using Active Directory Users and Computers.

Create the service account with these properties:

  • Username: openvpn-service
  • Password: Use a strong password and set it to never expire
  • Account options: Disable "User must change password at next logon"
  • Permissions: Grant "Log on as a service" right

Add users to the VPN access group:

New-ADGroup -Name "VPN-Users" -GroupScope Global -GroupCategory Security -Path "OU=Groups,DC=example,DC=com"
Add-ADGroupMember -Identity "VPN-Users" -Members "john.doe","jane.smith"

Configure client certificate template

Create a basic client certificate that all LDAP-authenticated users will share. This provides the TLS encryption while LDAP handles authentication.

cd /etc/openvpn/easy-rsa
sudo ./easyrsa gen-req client nopass
sudo ./easyrsa sign-req client client

Create the client configuration template:

client
dev tun
proto udp
remote vpn.example.com 1194
resolv-retry infinite
nobind
persist-key
persist-tun

auth-user-pass
cipher AES-256-GCM
auth SHA256
tls-version-min 1.2

comp-lzo
verb 3

<ca>
-----BEGIN CERTIFICATE-----

Copy content from /etc/openvpn/ca.crt

-----END CERTIFICATE----- </ca> <cert> -----BEGIN CERTIFICATE-----

Copy content from /etc/openvpn/easy-rsa/pki/issued/client.crt

-----END CERTIFICATE----- </cert> <key> -----BEGIN PRIVATE KEY-----

Copy content from /etc/openvpn/easy-rsa/pki/private/client.key

-----END PRIVATE KEY----- </key> <tls-auth> -----BEGIN OpenVPN Static key V1-----

Copy content from /etc/openvpn/ta.key

-----END OpenVPN Static key V1----- </tls-auth> key-direction 1

Enable IP forwarding and configure firewall

Enable packet forwarding so VPN clients can access network resources and configure firewall rules.

echo 'net.ipv4.ip_forward=1' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

Configure firewall rules for OpenVPN:

sudo ufw allow 1194/udp
sudo ufw allow OpenSSH
sudo ufw --force enable

Add NAT rule for VPN traffic:

# Add these lines after the header comments
*nat
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -s 10.8.0.0/8 -o eth0 -j MASQUERADE
COMMIT
sudo firewall-cmd --permanent --add-port=1194/udp
sudo firewall-cmd --permanent --add-masquerade
sudo firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=10.8.0.0/24 masquerade'
sudo firewall-cmd --reload

Set secure permissions and start OpenVPN

Set appropriate permissions on configuration files and start the OpenVPN service.

sudo chmod 600 /etc/openvpn/auth-ldap.conf
sudo chown root:root /etc/openvpn/auth-ldap.conf
sudo chmod 644 /etc/openvpn/server.conf
Never use chmod 777. It gives every user on the system full access to your files. OpenVPN configuration files contain sensitive authentication details that should only be readable by root.

Enable and start OpenVPN:

sudo systemctl enable openvpn@server
sudo systemctl start openvpn@server
sudo systemctl status openvpn@server

Configure group-based access policies

Set up different access levels for different AD groups by creating custom authorization scripts.

#!/bin/bash

Group-based authorization script

USERNAME="$1" GROUP_DN="$2"

Define group access policies

case "$GROUP_DN" in "VPN-Admins") # Full access for admin group echo "push 'route 192.168.1.0 255.255.255.0'" echo "push 'route 10.0.0.0 255.255.255.0'" exit 0 ;; "VPN-Users") # Limited access for regular users echo "push 'route 192.168.1.0 255.255.255.0'" exit 0 ;; *) # Deny access for users not in authorized groups exit 1 ;; esac

Make the script executable and update the server configuration:

sudo chmod 755 /etc/openvpn/group-auth.sh
sudo chown root:root /etc/openvpn/group-auth.sh

Add the authorization script to your server configuration:

# Add this line to enable group-based authorization
client-connect /etc/openvpn/group-auth.sh

Verify your setup

Test the LDAP connection and OpenVPN service functionality:

sudo systemctl status openvpn@server
sudo tail -f /var/log/openvpn.log

Test LDAP connectivity to your Domain Controller:

ldapsearch -x -H ldaps://dc1.example.com:636 -D "CN=openvpn-service,OU=Service Accounts,DC=example,DC=com" -W -b "OU=Users,DC=example,DC=com" "(sAMAccountName=testuser)"

Check that the OpenVPN server is listening on the correct port:

sudo netstat -tulpn | grep 1194
sudo ss -tulpn | grep 1194

Test client connection by importing the client configuration file into an OpenVPN client and connecting with AD credentials.

Common issues

SymptomCauseFix
LDAP bind failsIncorrect service account credentialsVerify BindDN and BindPW in auth-ldap.conf
User authentication rejectedUser not in required AD groupAdd user to VPN-Users group in Active Directory
SSL/TLS handshake failedCertificate issues or cipher mismatchCheck certificate validity and cipher compatibility
Plugin loading errorLDAP plugin not foundInstall openvpn-auth-ldap package
DNS resolution fails for LDAPCannot reach Domain ControllerVerify network connectivity and DNS settings
Permission denied on config filesIncorrect file ownership/permissionsUse sudo chown root:root and chmod 600 for sensitive configs

Next steps

Running this in production?

Want this handled for you? Running this at scale adds a second layer of work: capacity planning, failover drills, cost control, and on-call. See how we run infrastructure like this for European teams.

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle infrastructure security hardening for businesses that depend on uptime. From initial setup to ongoing operations.