Configure OpenVPN LDAP authentication for enterprise users with Active Directory integration

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

Set up OpenVPN server with LDAP authentication against Active Directory, enabling centralized user management and group-based access control for enterprise VPN deployments.

Prerequisites

  • Root or sudo access
  • Active Directory server accessible
  • Dedicated service account in AD
  • Firewall access to AD server port 389

What this solves

This tutorial configures OpenVPN server with LDAP authentication to integrate with your existing Active Directory infrastructure. Instead of managing VPN users separately, you'll authenticate users against AD with group-based access control and automated certificate management.

Step-by-step configuration

Update system packages

Start by updating your package manager to ensure you get the latest versions of OpenVPN and required dependencies.

sudo apt update && sudo apt upgrade -y
sudo dnf update -y

Install OpenVPN and LDAP authentication plugin

Install OpenVPN server, Easy-RSA for certificate management, and the LDAP authentication plugin that connects to Active Directory.

sudo apt install -y openvpn easy-rsa openvpn-auth-ldap libldap2-dev
sudo dnf install -y openvpn easy-rsa openvpn-auth-ldap openldap-devel

Set up Certificate Authority and server certificates

Create a Certificate Authority to manage VPN certificates. This CA will sign the server certificate and any client certificates if needed.

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 CA certificate

Initialize the Public Key Infrastructure and create the root Certificate Authority that will sign all certificates.

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

Generate server certificate and DH parameters

Create the server certificate and Diffie-Hellman parameters for secure key exchange. The server certificate identifies your VPN server.

sudo ./easyrsa build-server-full server nopass
sudo ./easyrsa gen-dh
sudo openvpn --genkey --secret pki/ta.key

Copy certificates to OpenVPN directory

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

sudo cp pki/ca.crt pki/issued/server.crt pki/private/server.key pki/dh.pem pki/ta.key /etc/openvpn/server/
sudo chown root:root /etc/openvpn/server/*
sudo chmod 600 /etc/openvpn/server/server.key /etc/openvpn/server/ta.key
sudo chmod 644 /etc/openvpn/server/ca.crt /etc/openvpn/server/server.crt /etc/openvpn/server/dh.pem

Create OpenVPN server configuration

Configure the OpenVPN server with LDAP authentication enabled. This configuration listens on port 1194 and uses the LDAP plugin for user authentication.

port 1194
proto udp
dev tun

ca ca.crt
cert server.crt
key server.key
dh dh.pem
tls-auth ta.key 0

server 10.8.0.0 255.255.255.0
ifconfig-pool-persist /var/log/openvpn/ipp.txt

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

keepalive 10 120
tls-crypt ta.key
cipher AES-256-GCM
auth SHA256

user nobody
group nogroup

persist-key
persist-tun

status /var/log/openvpn/openvpn-status.log
log-append /var/log/openvpn/openvpn.log
verb 3
explicit-exit-notify 1

LDAP Authentication

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

Configure LDAP authentication plugin

Create the LDAP authentication configuration to connect to your Active Directory server. Replace the values with your AD server details.

<LDAP>
    # LDAP server URL - replace with your domain controller
    URL             ldap://dc1.example.com:389
    
    # Bind credentials for LDAP search
    BindDN          "CN=vpn-service,CN=Users,DC=example,DC=com"
    Password        "SecureServiceAccountPassword"
    
    # Connection timeout
    Timeout         15
    
    # Follow LDAP referrals
    FollowReferrals yes
    
    # TLS configuration (uncomment for secure LDAP)
    # TLSEnable       yes
    # TLSCACertFile   /etc/ssl/certs/ca-certificates.crt
</LDAP>

<Authorization>
    # Base DN for user searches
    BaseDN          "CN=Users,DC=example,DC=com"
    
    # Search filter for users
    SearchFilter    "(&(objectClass=user)(sAMAccountName=%u)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))"
    
    # Require group membership for access
    RequireGroup    true
    
    <Group>
        # Base DN for group searches
        BaseDN      "CN=Users,DC=example,DC=com"
        
        # Group search filter - only allow VPN Users group
        SearchFilter "(&(objectClass=group)(cn=VPN Users))"
        
        # Group membership attribute
        MemberAttribute member
        
        # Group member format
        MemberAttributeIsDN true
    </Group>
</Authorization>

Create service account in Active Directory

Create a dedicated service account in Active Directory for OpenVPN LDAP authentication. This account needs read permissions on user and group objects.

Note: Run these commands on your domain controller or use Active Directory Users and Computers GUI to create the vpn-service account with a strong password.

Create VPN Users group in Active Directory

Create a security group to control VPN access. Only users in this group will be able to authenticate to the VPN.

Note: Create a group named "VPN Users" in Active Directory and add the users who should have VPN access to this group.

Set up OpenVPN log directory

Create the log directory for OpenVPN with appropriate permissions for the nobody user.

sudo mkdir -p /var/log/openvpn
sudo chown nobody:nogroup /var/log/openvpn
sudo chmod 755 /var/log/openvpn

Configure IP forwarding and firewall

Enable IP forwarding to route VPN traffic and configure firewall rules to allow VPN connections and NAT.

echo 'net.ipv4.ip_forward=1' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
sudo ufw allow 1194/udp
sudo ufw allow OpenSSH
sudo ufw --force enable

Configure NAT for VPN traffic

echo 'net/ipv4/ip_forward=1' | sudo tee -a /etc/ufw/sysctl.conf sudo sed -i '1i# NAT for OpenVPN\n*nat\n:POSTROUTING ACCEPT [0:0]\n-A POSTROUTING -s 10.8.0.0/8 -o eth0 -j MASQUERADE\nCOMMIT\n' /etc/ufw/before.rules
sudo firewall-cmd --permanent --add-service=openvpn
sudo firewall-cmd --permanent --add-masquerade
sudo firewall-cmd --permanent --direct --passthrough ipv4 -t nat -A POSTROUTING -s 10.8.0.0/8 -o eth0 -j MASQUERADE
sudo firewall-cmd --reload

Enable and start OpenVPN service

Enable the OpenVPN service to start automatically on boot and start it now.

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

Create client configuration template

Create a base client configuration that users can download and configure with their credentials.

client
dev tun
proto udp
remote your-server-ip 1194
resolv-retry infinite
nobind
user nobody
group nogroup
persist-key
persist-tun
remote-cert-tls server
cipher AES-256-GCM
auth SHA256
verb 3
auth-user-pass

<ca>

Paste contents of /etc/openvpn/server/ca.crt here

</ca> <tls-crypt>

Paste contents of /etc/openvpn/server/ta.key here

</tls-crypt>

Test LDAP authentication

Test LDAP connection manually

Verify that the LDAP authentication is working by testing the connection to your Active Directory server.

sudo apt install -y ldap-utils
ldapsearch -x -H ldap://dc1.example.com:389 -D "CN=vpn-service,CN=Users,DC=example,DC=com" -W -b "CN=Users,DC=example,DC=com" "(sAMAccountName=testuser)"

Check OpenVPN logs for authentication attempts

Monitor the OpenVPN logs to see authentication attempts and troubleshoot any LDAP connection issues.

sudo tail -f /var/log/openvpn/openvpn.log

Configure group-based access control

Create multiple VPN groups for different access levels

Configure different groups for various access levels like full access, restricted access, or department-specific access.

<LDAP>
    URL             ldap://dc1.example.com:389
    BindDN          "CN=vpn-service,CN=Users,DC=example,DC=com"
    Password        "SecureServiceAccountPassword"
    Timeout         15
    FollowReferrals yes
</LDAP>

<Authorization>
    BaseDN          "CN=Users,DC=example,DC=com"
    SearchFilter    "(&(objectClass=user)(sAMAccountName=%u)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))"
    RequireGroup    true
    
    # Full access VPN group
    <Group>
        BaseDN      "CN=Users,DC=example,DC=com"
        SearchFilter "(&(objectClass=group)(cn=VPN Full Access))"
        MemberAttribute member
        MemberAttributeIsDN true
    </Group>
    
    # IT Department VPN access
    <Group>
        BaseDN      "CN=Users,DC=example,DC=com"
        SearchFilter "(&(objectClass=group)(cn=VPN IT Department))"
        MemberAttribute member
        MemberAttributeIsDN true
    </Group>
</Authorization>

Configure client-specific configurations

Set up client-specific configurations based on group membership to provide different network access levels.

sudo mkdir -p /etc/openvpn/ccd
sudo chown root:root /etc/openvpn/ccd
sudo chmod 755 /etc/openvpn/ccd

Add this line to your server configuration to enable client-specific configurations:

# Add this line to the existing server.conf
client-config-dir /etc/openvpn/ccd

Verify your setup

sudo systemctl status openvpn-server@server
sudo netstat -tlunp | grep :1194
sudo tail -20 /var/log/openvpn/openvpn.log
ldapsearch -x -H ldap://dc1.example.com:389 -D "CN=vpn-service,CN=Users,DC=example,DC=com" -W -b "CN=Users,DC=example,DC=com" "(cn=VPN Users)"

Common issues

SymptomCauseFix
LDAP bind failedWrong service account credentialsVerify BindDN and password in auth-ldap.conf
User authentication failsUser not in VPN groupAdd user to "VPN Users" group in Active Directory
Can't connect to LDAP serverFirewall blocking port 389Allow port 389/tcp from OpenVPN server to domain controller
Certificate verification failedMissing or wrong certificatesRegenerate certificates with sudo ./easyrsa build-server-full server nopass
No internet access through VPNIP forwarding or NAT not configuredCheck net.ipv4.ip_forward=1 and firewall NAT rules
Plugin load failedLDAP plugin not installedInstall openvpn-auth-ldap package

Next steps

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.