Configure LDAP authentication for centralized user management with OpenLDAP and SSSD

Intermediate 45 min May 09, 2026 81 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Set up centralized user authentication using OpenLDAP server with SSSD client integration. Configure PAM and NSS for seamless login across multiple Linux systems with directory-based user management.

Prerequisites

  • Root or sudo access
  • Basic understanding of Linux user management
  • Network connectivity between LDAP server and clients

What this solves

LDAP authentication centralizes user management across multiple Linux systems, eliminating the need to maintain local user accounts on each server. When you have multiple servers and users need access to different systems, managing accounts individually becomes unwieldy. This tutorial configures OpenLDAP as the directory server and SSSD as the client to handle authentication, authorization, and user information lookups.

Step-by-step installation

Update system packages

Start by updating your package manager to ensure you get the latest versions of all components.

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

Install OpenLDAP server

Install the OpenLDAP server packages and utilities. This sets up the directory server that will store user accounts and authentication information.

sudo apt install -y slapd ldap-utils
sudo dnf install -y openldap-servers openldap-clients

Configure OpenLDAP domain and admin password

Run the initial configuration to set your domain and administrator password. Replace example.com with your actual domain.

sudo dpkg-reconfigure slapd
sudo cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
sudo chown ldap:ldap /var/lib/ldap/DB_CONFIG
sudo systemctl enable --now slapd
Configuration options: Select "No" for omitting OpenLDAP server configuration, enter your domain (example.com), organization name, set a strong admin password, and choose MDB as the database backend.

Create base LDAP structure

Create the organizational units for users and groups. This establishes the directory structure where user accounts will be stored.

dn: ou=users,dc=example,dc=com
objectClass: organizationalUnit
ou: users

dn: ou=groups,dc=example,dc=com
objectClass: organizationalUnit
ou: groups
ldapadd -x -D cn=admin,dc=example,dc=com -W -f /tmp/base.ldif

Create test user account

Add a test user to verify the LDAP directory is working. This user will authenticate through LDAP on client systems.

dn: uid=testuser,ou=users,dc=example,dc=com
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
uid: testuser
cn: Test User
sn: User
givenName: Test
mail: testuser@example.com
uidNumber: 10001
gidNumber: 10001
homeDirectory: /home/testuser
loginShell: /bin/bash
userPassword: {SSHA}generatedpasswordhash
slappasswd -h {SSHA}

Copy the generated hash and replace {SSHA}generatedpasswordhash in the LDIF file

ldapadd -x -D cn=admin,dc=example,dc=com -W -f /tmp/testuser.ldif

Install SSSD on client systems

Install SSSD and related packages on systems that need to authenticate against LDAP. SSSD handles the communication with the LDAP server and caches credentials.

sudo apt install -y sssd sssd-ldap ldap-utils
sudo dnf install -y sssd sssd-ldap openldap-clients

Configure SSSD for LDAP authentication

Create the SSSD configuration file to connect to your LDAP server. This tells SSSD where to find user accounts and how to authenticate them.

[sssd]
config_file_version = 2
domains = example.com
services = nss, pam

[domain/example.com]
id_provider = ldap
auth_provider = ldap
ldap_uri = ldap://192.168.1.10
ldap_search_base = dc=example,dc=com
ldap_user_search_base = ou=users,dc=example,dc=com
ldap_group_search_base = ou=groups,dc=example,dc=com
ldap_default_bind_dn = cn=admin,dc=example,dc=com
ldap_default_authtok = your_admin_password
cache_credentials = true
enumerate = false
sudo chmod 600 /etc/sssd/sssd.conf
sudo systemctl enable --now sssd

Configure PAM for LDAP authentication

Update PAM configuration to use SSSD for authentication. This enables LDAP users to log in using their directory credentials.

sudo pam-auth-update --enable mkhomedir
sudo authselect enable-feature with-mkhomedir
sudo systemctl enable --now oddjobd

Configure NSS to use SSSD

Update the Name Service Switch configuration to query SSSD for user and group information. This allows the system to resolve LDAP users and groups.

# Edit these lines in /etc/nsswitch.conf
passwd:         files systemd sss
group:          files systemd sss
shadow:         files sss
sudo systemctl restart sssd

Configure automatic home directory creation

Enable automatic creation of home directories when LDAP users log in for the first time. This ensures users have a proper home directory structure.

# Add this line to /etc/pam.d/common-session
session required pam_mkhomedir.so skel=/etc/skel umask=0022
# Add this line to /etc/pam.d/system-auth session section
session required pam_mkhomedir.so skel=/etc/skel umask=0022

Configure TLS encryption

Generate SSL certificates for LDAP

Create SSL certificates to encrypt LDAP communication. This protects user credentials in transit between clients and the LDAP server.

sudo mkdir -p /etc/ssl/ldap
sudo openssl req -new -x509 -nodes -out /etc/ssl/ldap/ldap-server.pem -keyout /etc/ssl/ldap/ldap-server.key -days 365 -subj "/C=US/ST=State/L=City/O=Organization/CN=ldap.example.com"
sudo chown openldap:openldap /etc/ssl/ldap/*
sudo chmod 600 /etc/ssl/ldap/ldap-server.key

Configure OpenLDAP for TLS

Enable TLS in the OpenLDAP configuration using the certificates you just created.

dn: cn=config
changetype: modify
add: olcTLSCertificateFile
olcTLSCertificateFile: /etc/ssl/ldap/ldap-server.pem
-
add: olcTLSCertificateKeyFile
olcTLSCertificateKeyFile: /etc/ssl/ldap/ldap-server.key
-
add: olcTLSCipherSuite
olcTLSCipherSuite: HIGH:!aNULL:!MD5
sudo ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/tls.ldif
sudo systemctl restart slapd

Update SSSD for TLS connection

Modify the SSSD configuration to use encrypted LDAP connections.

[domain/example.com]
id_provider = ldap
auth_provider = ldap
ldap_uri = ldaps://192.168.1.10:636
ldap_search_base = dc=example,dc=com
ldap_user_search_base = ou=users,dc=example,dc=com
ldap_group_search_base = ou=groups,dc=example,dc=com
ldap_default_bind_dn = cn=admin,dc=example,dc=com
ldap_default_authtok = your_admin_password
ldap_tls_reqcert = allow
cache_credentials = true
enumerate = false
sudo systemctl restart sssd

Verify your setup

Test that LDAP authentication is working correctly on both server and client systems.

# Test LDAP server connectivity
ldapsearch -x -H ldap://192.168.1.10 -D cn=admin,dc=example,dc=com -W -b dc=example,dc=com

Test SSSD user resolution

getent passwd testuser id testuser

Check SSSD status

sudo systemctl status sssd sudo sss_cache -E

Test authentication (if configured for SSH)

ssh testuser@localhost

Common issues

SymptomCauseFix
getent passwd shows no LDAP usersSSSD not connecting to LDAPCheck /var/log/sssd/sssd_example.com.log and verify LDAP URI and credentials
Authentication failed for LDAP userWrong bind DN or passwordTest with ldapwhoami -x -D uid=testuser,ou=users,dc=example,dc=com -W
Home directory not created on loginpam_mkhomedir not configuredAdd mkhomedir to PAM configuration and restart SSSD
LDAP server not startingDatabase permission issuessudo chown -R openldap:openldap /var/lib/ldap
TLS connection failingCertificate issuesCheck certificate paths and permissions, use ldap_tls_reqcert = allow for testing
Users can't sudoNo sudo privileges configuredAdd LDAP users to sudo group or configure LDAP-based sudo rules

Next steps

Running this in production?

Need this managed professionally? Setting this up once is straightforward. Keeping it patched, monitored, backed up and performant across environments is the harder part. See how we run infrastructure like this for European teams who need reliable directory services.

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.