DebianDebian Based

How To Install OpenLDAP on Debian 13

Install OpenLDAP on Debian 13

Managing user accounts across multiple Linux servers one by one is not scalable. It is tedious, error-prone, and a security risk waiting to happen. That is exactly why OpenLDAP exists. It gives system administrators a centralized directory service to manage users, groups, and authentication from a single point of control — across every server in the network.

This guide walks you through the complete installation and configuration of OpenLDAP on Debian 13 (Trixie), the latest stable release in the Debian family. Whether you are setting up a home lab, a small business infrastructure, or preparing for a larger enterprise deployment, every step here is practical, tested, and ready to run.

What Is OpenLDAP and Why Does It Matter?

OpenLDAP is an open-source implementation of the Lightweight Directory Access Protocol (LDAP) — a standard protocol used to access and maintain distributed directory information services over an IP network. Think of it as a phone book for your infrastructure: every user, device, and group has a record, and any authorized system can look up that information instantly.

The OpenLDAP suite has two core components you will interact with throughout this guide:

  • slapd (Stand-Alone LDAP Daemon) — the server process that handles all directory operations
  • ldap-utils — a collection of command-line client tools for querying, modifying, and managing the directory

Common use cases include centralized authentication, Single Sign-On (SSO), network resource management, and user provisioning across Linux systems. OpenLDAP is the default choice for teams that need something lightweight, highly customizable, and fully open-source — without the overhead of solutions like FreeIPA or Microsoft Active Directory.

Prerequisites

Before starting the installation, make sure the following conditions are in place:

  • A server or virtual machine running Debian 13 (Trixie) — a fresh install is strongly recommended
  • Root or sudo access on the system
  • A configured Fully Qualified Domain Name (FQDN), for example ldap.example.local
  • A static IP address assigned to the server
  • Ports 389 (LDAP) and 636 (LDAPS) available and not blocked by an external firewall
  • Minimum specs: 1 vCPU, 1 GB RAM, 10 GB disk (suitable for lab and small production setups)

Step 1 — Update Your Debian 13 System

Always start with a full system update. It ensures package indexes are fresh and prevents dependency conflicts during installation — a step that many people skip and later regret.

Run:

sudo apt update && sudo apt upgrade -y

Confirm that your system is running Debian 13 Trixie:

lsb_release -a

The output should show:

Distributor ID: Debian
Description:    Debian GNU/Linux 13 (trixie)
Codename:       trixie

If the system applied a kernel update, reboot before proceeding:

sudo reboot

Step 2 — Install slapd and ldap-utils

With the system updated, install the OpenLDAP server package and the client utilities in one command:

sudo apt -y install slapd ldap-utils

During installation, Debian will display an ncurses dialog asking you to set the LDAP administrator password. This is the password that controls access to the directory root, so choose a strong one — at least 12 characters with mixed case, numbers, and symbols.

┌─────────────── Configuring slapd ───────────────┐
│ Please enter the password for the admin entry   │
│ in your LDAP directory.                         │
│                                                 │
│ Administrator password: ___________________     │
└─────────────────────────────────────────────────┘

Once installed, Debian automatically infers the LDAP suffix from the system hostname. Verify the installation worked by running slapcat, a tool that reads the directory database directly:

sudo slapcat

You should see output like:

dn: dc=example,dc=local
objectClass: top
objectClass: dcObject
objectClass: organization
o: example.local
dc: example

That confirms slapd is running and the backend MDB database was created successfully.

Step 3 — Reconfigure OpenLDAP with dpkg-reconfigure

The auto-generated suffix may not match your desired domain structure. Use dpkg-reconfigure to customize it fully:

sudo dpkg-reconfigure slapd

Work through the interactive prompts:

  1. Omit OpenLDAP server configuration? → Select No
  2. DNS domain name? → Enter your domain, e.g., example.local
  3. Organization name? → Enter your org name, e.g., Example Organization
  4. Administrator password? → Enter and confirm a strong password
  5. Remove the database when slapd is purged? → Select No
  6. Move old database? → Select Yes

⚠️ Important: Never select “Yes” to purging the database on a production server. That action is irreversible and will destroy your entire directory.

Restart the service to apply changes:

sudo systemctl restart slapd

Run slapcat one more time to confirm the new suffix is in place.

Step 4 — Verify the slapd Service Status

Check that the slapd daemon is active and configured to start automatically at boot:

sudo systemctl status slapd
sudo systemctl enable slapd

The status output should show Active: active (running).

Next, confirm OpenLDAP is listening on the correct ports:

ss -altnp | grep slapd

You should see 0.0.0.0:389 (LDAP) and 0.0.0.0:636 (LDAPS) in the LISTEN state. If those ports are missing, the daemon did not start correctly — check journalctl -u slapd for error details.

Step 5 — Add Base DN for Users and Groups

A Base DN (Distinguished Name) is the root of your directory tree. Beneath it, you organize entries into Organizational Units (OUs). The two most fundamental OUs are people (for user accounts) and groups (for group records).

Create a new LDIF file:

nano base.ldif

Paste the following, replacing the domain components with your own:

dn: ou=people,dc=example,dc=local
objectClass: organizationalUnit
ou: people

dn: ou=groups,dc=example,dc=local
objectClass: organizationalUnit
ou: groups

Add the entries to the directory:

ldapadd -x -D cn=admin,dc=example,dc=local -W -f base.ldif

The flags here are worth understanding. The -x flag uses simple authentication, -D specifies the bind DN (the admin account), and -W prompts for the admin password interactively.

Verify the OUs were created:

ldapsearch -x -LLL -b dc=example,dc=local

You should see both ou=people and ou=groups returned in the output.

Step 6 — Add LDAP User Accounts to the Directory

Now populate the directory with actual user accounts. First, generate a hashed password for the new user:

sudo slappasswd

Copy the {SSHA} hash that is generated. Then create a user LDIF file:

nano users.ldif

Insert the following entry, customizing it with real user details:

dn: uid=johndoe,ou=people,dc=example,dc=local
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
uid: johndoe
cn: John
sn: Doe
userPassword: {SSHA}YourHashedPasswordHere
loginShell: /bin/bash
uidNumber: 10000
gidNumber: 10000
homeDirectory: /home/johndoe
shadowLastChange: 0
shadowMax: 0
shadowWarning: 0

The three objectClass entries serve distinct roles: inetOrgPerson provides standard contact attributes, posixAccount maps the user to a Linux system account, and shadowAccount enables password aging and expiry policies.

Use uidNumber and gidNumber starting at 10000 or higher — this keeps LDAP users clearly separated from local system accounts, which typically occupy IDs below 1000.

Add the user to the directory:

ldapadd -x -D cn=admin,dc=example,dc=local -W -f users.ldif

Verify the user appears under the people OU:

ldapsearch -x -LLL -b ou=people,dc=example,dc=local

Step 7 — Secure OpenLDAP with TLS/SSL

Standard LDAP transmits credentials in plaintext. That is completely unacceptable on any network you do not fully control. Enabling TLS encrypts the entire communication channel between clients and the LDAP server.

Generate a self-signed certificate (suitable for development; use a CA-signed cert in production):

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
  -keyout /etc/ssl/ldapserver.key \
  -out /etc/ssl/ldapserver.crt

Set proper ownership so the slapd process can read the certificate files:

sudo chown ldap:ldap /etc/ssl/ldapserver.crt
sudo chown ldap:ldap /etc/ssl/ldapserver.key

Create a TLS configuration LDIF file:

nano tls.ldif
dn: cn=config
changetype: modify
add: olcTLSCACertificateFile
olcTLSCACertificateFile: /etc/ssl/ldapserver.crt
-
add: olcTLSCertificateFile
olcTLSCertificateFile: /etc/ssl/ldapserver.crt
-
add: olcTLSCertificateKeyFile
olcTLSCertificateKeyFile: /etc/ssl/ldapserver.key

Apply the TLS configuration:

sudo ldapmodify -Y EXTERNAL -H ldapi:/// -f tls.ldif

Update /etc/ldap/ldap.conf to reference the certificate:

echo "TLS_CACERT /etc/ssl/ldapserver.crt" | sudo tee -a /etc/ldap/ldap.conf

Restart slapd and verify TLS attributes were applied:

sudo systemctl restart slapd
sudo slapcat -b "cn=config" | grep -i tls

Production tip: For internet-facing deployments, use a certificate from Let’s Encrypt or your organization’s internal PKI. Self-signed certificates generate TLS warnings in clients and are not appropriate for regulated environments.

Step 8 — Configure UFW Firewall for OpenLDAP

Protecting the LDAP service at the network level is just as important as TLS. Set up UFW to allow only the necessary traffic:

sudo apt install ufw -y
sudo ufw allow OpenSSH
sudo ufw enable

Allow LDAP and LDAPS ports:

sudo ufw allow LDAP
sudo ufw allow LDAPS

For tighter security in production, restrict access to specific IP ranges rather than opening these ports to the entire internet:

sudo ufw allow from 192.168.1.0/24 to any port 389
sudo ufw allow from 192.168.1.0/24 to any port 636

Reload and verify:

sudo ufw reload
sudo ufw status verbose

An unrestricted LDAP port on a public IP address is one of the most common misconfigurations in Linux server deployments. It allows attackers to enumerate usernames and organizational structure through anonymous binds. Always restrict access.

Step 9 — Enable Logging for OpenLDAP

By default, OpenLDAP logs very little. Enabling stats-level logging gives you visibility into every connection, bind operation, and search — which is invaluable for debugging and auditing.

Use ldapmodify to set the log level:

sudo ldapmodify -Y EXTERNAL -H ldapi:/// -Q << EOF
dn: cn=config
changetype: modify
replace: olcLogLevel
olcLogLevel: stats
EOF

Verify the log level was applied:

sudo ldapsearch -Y EXTERNAL -H ldapi:/// -b cn=config \
  "(objectClass=olcGlobal)" olcLogLevel -LLL -Q

View live LDAP logs with:

journalctl -f -u slapd

For persistent log storage, configure rsyslog to write slapd output to /var/log/slapd.log using the local4 facility. This makes log rotation and retention management much cleaner on long-running servers.

Step 10 — Test the OpenLDAP Installation

With everything configured, run a series of tests to confirm the directory is fully operational.

Anonymous search (tests basic connectivity):

ldapsearch -x -b dc=example,dc=local -H ldap://localhost

Authenticated search as the admin user:

ldapsearch -x -D "cn=admin,dc=example,dc=local" -W \
  -b "dc=example,dc=local"

LDAPS (TLS-encrypted) search — tests the TLS layer specifically:

ldapsearch -x -H ldaps://localhost \
  -D "cn=admin,dc=example,dc=local" -W \
  -b "dc=example,dc=local"

All three tests should return the directory tree including ou=people, ou=groups, and the user johndoe. If the plain LDAP search works but LDAPS fails, the issue is isolated to your TLS certificate configuration — recheck file paths and ownership.

Common Errors and Troubleshooting Tips

Even a careful installation can hit unexpected issues. Here are the most common problems and how to resolve them quickly:

Error Likely Cause Fix
Can't contact LDAP server slapd not running or wrong host Run sudo systemctl restart slapd and check ss -tlnp
Invalid credentials (49) Wrong admin password or bind DN Reset via sudo dpkg-reconfigure slapd
Insufficient access (50) Misconfigured ACL rules Review olcAccess entries in cn=config with slapcat
TLS handshake failure Certificate path or permission mismatch Recheck tls.ldif paths and run chown ldap:ldap on cert files
No such object (32) Base DN does not exist yet Re-run ldapadd with base.ldif
Already exists (68) Entry already in the directory Use ldapmodify instead of ldapadd for existing entries

Before restarting slapd after any configuration change, always validate the config first:

sudo slaptest -u

This command checks the integrity of the slapd.d configuration directory without restarting the daemon. It is a simple habit that saves a lot of downtime.

Congratulations! You have successfully installed OpenLDAP. Thanks for using this tutorial for installing the latest version of OpenLDAP on Debian 12 “Trixie” system. For additional help or useful information, we recommend you check the official OpenLDAP website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button