👥
Directory Server

OpenLDAP

Lightweight directory access protocol for centralized user and group management

🐧 Linux🍎 Mac🪟 Windows
Reviewed: Tested on: Kubernetes 1.29 · Terraform 1.8 · Ubuntu 22.04

What is this?

LDAP stores user accounts and passwords in one central directory used for logins across systems.

📥

Step 01

Install OpenLDAP

(01)Install OpenLDAP server

Linux
1# Ubuntu / Debian
2sudo apt-get install -y slapd ldap-utils
3
4# During install, set admin password (dc=example,dc=com)
5
6# RHEL / Fedora
7sudo dnf install -y openldap-servers openldap-clients
8sudo systemctl enable --now slapd
⚙️

Step 02

Configure LDAP

(01)Reconfigure base DN and admin

Linux
1sudo dpkg-reconfigure slapd
2# DNS domain name: example.com
3# Organization: Example Inc
4# Admin password: (your password)
5
6# Verify config
7sudo slapcat | head -20

(02)Add organizational units and users

Linux
1# Create OU structure LDIF
2cat > ou.ldif << 'EOF'
3dn: ou=people,dc=example,dc=com
4objectClass: organizationalUnit
5ou: people
6
7dn: ou=groups,dc=example,dc=com
8objectClass: organizationalUnit
9ou: groups
10EOF
11
12sudo ldapadd -x -D "cn=admin,dc=example,dc=com" -W -f ou.ldif
13
14# Add user
15cat > user.ldif << 'EOF'
16dn: uid=john,ou=people,dc=example,dc=com
17objectClass: inetOrgPerson
18uid: john
19sn: Doe
20cn: John Doe
21userPassword: {SSHA}password_hash
22mail: john@example.com
23EOF
24
25# Generate password hash:
26slappasswd -s mypassword
27sudo ldapadd -x -D "cn=admin,dc=example,dc=com" -W -f user.ldif

(03)Configure LDAP client (Linux)

Linux
1sudo apt-get install -y libnss-ldap libpam-ldap nscd
2
3sudo nano /etc/ldap/ldap.conf
4# BASE dc=example,dc=com
5# URI ldap://192.168.1.10
6
7sudo nano /etc/nsswitch.conf
8# passwd: files ldap
9# group: files ldap
10# shadow: files ldap
11
12sudo systemctl restart nscd
13getent passwd john

Step 03

Verify LDAP

(01)Search directory

Linux
1ldapsearch -x -H ldap://localhost -b "dc=example,dc=com" -D "cn=admin,dc=example,dc=com" -W
2ldapwhoami -x -H ldap://localhost -D "uid=john,ou=people,dc=example,dc=com" -W

Step 04

Manage LDAP

(01)Modify and delete entries

Linux
1# Modify user
2cat > modify.ldif << 'EOF'
3dn: uid=john,ou=people,dc=example,dc=com
4changetype: modify
5replace: mail
6mail: john.doe@example.com
7EOF
8ldapmodify -x -D "cn=admin,dc=example,dc=com" -W -f modify.ldif
9
10# Delete user
11ldapdelete -x -D "cn=admin,dc=example,dc=com" -W "uid=john,ou=people,dc=example,dc=com"