Setting Up an LDAP Service
Setting up an LDAP (Lightweight Directory Access Protocol) server is a core step in implementing enterprise-level centralised identity authentication and permission management. The most commonly used open-source implementation is OpenLDAP.
Below are detailed steps for setting up an OpenLDAP server on Debian/Ubuntu-based Linux systems.
Environment Preparation and Installation
Before starting, ensure your system packages are up to date and the hostname is properly configured.
During installation, you will be prompted to set the LDAP administrator password. Be sure to remember this password — it will be used frequently during configuration.
Configuring the OpenLDAP Server
Although the installation performs some initial setup, we typically need to customise the configuration for a specific domain (e.g., example.com).
Reconfigure slapd
Run the following command to enter the interactive configuration interface:
Configuration recommendations:
- Omit OpenLDAP server configuration? Choose No.
- DNS domain name: Enter your domain (e.g.,
centre.example.com). This determines your Base DN, such asdc=centre,dc=example,dc=com. - Organization name: Enter your organisation name.
- Administrator password: Enter the administrator password you set earlier.
- Database backend: MDB is recommended.
- Remove database when slapd is purged? Choose No.
- Move old database? Choose Yes.
Understanding the LDAP Hierarchy
LDAP data is stored in a tree structure. To facilitate management, we typically create two "Organisational Units" (OUs): one for users (People) and one for groups (Groups).
Creating Organisational Units (OUs)
In LDAP, we use LDIF (LDAP Data Interchange Format) files to add or modify directory entries.
Create a file named base.ldif:
Import the data:
Adding Users and Groups
Create a file named groups.ldif to define a new group:
Create a file named users.ldif to define a new user:
If you plan to integrate GitLab, Jenkins, or a VPN later, they typically search the
uidattribute to verify login names.
FAQ
If the user doesn't need server login permissions, can the objectClass: posixAccount be removed?
Yes, it can be completely removed, but you need to be aware of the "binding relationships" between attributes.
If you only need this user for web application logins (e.g., GitLab, Jenkins, Wiki) or as an email contact, and they don't need to log into a Linux server via SSH or console, removing posixAccount is the more standard approach.
When you remove objectClass: posixAccount, the following attributes must also be deleted, as they belong to that class's mandatory or optional attributes:
uidNumbergidNumberhomeDirectoryloginShell
Additionally, shadowAccount is also typically associated with system logins — if you don't need to manage Linux password expiry policies, it can also be removed.
Follow-up Suggestions and Management Tools
Command-line LDAP management can be cumbersome. The following tools are recommended for visual administration:
- phpLDAPAdmin: A web-based management interface, ideal for quick onboarding.
- Apache Directory Studio: A powerful cross-platform desktop client, suitable for complex architecture design.
- Security Hardening: By default, LDAP transmits data in plain text. It is recommended to configure LDAPS (LDAP over SSL/TLS) to encrypt communication on port 636.