Install and bring up an OpenLDAP directory service, define a base DN, and initialize core directory entries using LDIF. Validate service health and confirm query results with ldapsearch before adding users and groups.
You are standardizing identity lookups across Linux systems and need a baseline directory service that can answer queries reliably. Your task is to install OpenLDAP, establish a base DN, and load initial directory structure so the environment has a known-good starting point.
LDAP becomes foundational quickly. Treat the base DN, schema state, and admin bind as baseline configuration, and verify each step before you start adding users and groups.
slapd is running and reachable locally.dc=example,dc=com
) and admin bind DN.
systemctl
).
slappasswd
.
core.ldif
).
ldapadd
).
ldapsearch
with scoped base DN queries.
# Debian/Ubuntu
sudo apt install slapd ldap-utils -y
# RHEL/Fedora family
sudo dnf install openldap-servers openldap-clients -y
# Arch
sudo pacman -S openldap
Install the server daemon and client tools so you can configure and validate the directory from the CLI. If you cannot run client queries locally, you do not have a reliable baseline to build on.
sudo dpkg-reconfigure slapd
On Debian/Ubuntu,
dpkg-reconfigure
drives initial configuration (domain, base DN, admin password, database backend).
On other distributions the initialization differs, but the target state is the same: a defined base DN and a working admin bind.
# Outcome (example):
slapd configured with your specified domain and base DN.
slappasswd
slappasswd
produces an SSHA hash suitable for LDAP password fields.
Use this when you are writing LDIF and need a hashed value instead of a plaintext secret.
{SSHA}REDACTED_HASH_OUTPUT
slapd is running under systemd.
sudo systemctl status slapd
This is your baseline service-health check. If
slapd
is not active, schema and LDIF operations are premature.
# Expected pattern:
slapd is active (running)
# Debian/Ubuntu schema path example:
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/core.ldif
# RHEL/Fedora schema path example:
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/core.ldif
Schema defines object types and attributes your directory can store. Some deployments have core schema loaded by default; others require explicit loading using SASL EXTERNAL over the local LDAPI socket.
core.ldif schema loaded successfully.
nano ~/base.ldif
# or
vim ~/base.ldif
This LDIF initializes the base DN entry for your directory.
Your DN must match the domain you configured; the lab uses
dc=example,dc=com
as a placeholder.
dn: dc=example,dc=com
objectClass: top
objectClass: dcObject
objectClass: organization
o: Example Company
dc: example
ldapadd.
ldapadd -x -D cn=admin,dc=example,dc=com -W -f ~/base.ldif
This performs a simple bind (
-x
) as the admin DN and adds the LDIF content into the directory.
In production you typically use TLS and may bind to a dedicated directory manager DN depending on the deployment model.
Base DN structure added to LDAP directory.
ldapsearch.
ldapsearch -x -LLL -b dc=example,dc=com
This performs a read-only search and returns entries under the base DN.
It validates that
slapd
is responding and your base entries exist.
# Expected pattern:
dn: dc=example,dc=com
objectClass: dcObject
objectClass: organization
...
If
systemctl status slapd
shows errors, do not proceed with schema or LDIF operations. Validate package install, check logs, and confirm the service unit is present and enabled.
This usually means the LDAPI socket is not available or permissions do not allow the EXTERNAL bind. Confirm
slapd
is running and that the
ldapi:///
endpoint exists on your system.
Confirm the bind DN matches your configured directory manager DN and that the base DN matches the directory domain. A mismatched DN is a common cause of failed binds in early setup.
This usually indicates the base LDIF was not applied or the search base is incorrect. Verify the DN in your LDIF and re-run the query with the exact base DN you configured.
This lab changes system state by installing packages and starting the directory service. If you are using a disposable environment, stop the service and remove packages when you are done.
# Stop the service (optional)
sudo systemctl stop slapd
# Remove packages (optional)
# Debian/Ubuntu
sudo apt remove --purge slapd ldap-utils -y
# RHEL/Fedora
sudo dnf remove openldap-servers openldap-clients -y
# Arch
sudo pacman -Rns openldap
apt install slapd ldap-utils
: Installs OpenLDAP server and client tools on Debian/Ubuntu.
slapd
: OpenLDAP directory server daemon.
ldap-utils
: Client utilities including
ldapadd
and
ldapsearch
.
dnf install openldap-servers openldap-clients
: Installs OpenLDAP server and client tools on RHEL/Fedora.
openldap-servers
: Server components for
slapd
.
openldap-clients
: Client utilities including
ldapadd
and
ldapsearch
.
pacman -S openldap
: Installs OpenLDAP on Arch-based systems.
-S
: Installs packages from sync repositories.
dpkg-reconfigure slapd
: Runs Debian/Ubuntu interactive initialization for
slapd
.
slappasswd
: Generates SSHA password hashes for LDAP configuration or LDIF use.
systemctl status slapd
: Shows service status for the OpenLDAP daemon.
status
: Displays current unit state and recent log lines.
ldapadd -Y EXTERNAL -H ldapi:/// -f <file.ldif>
: Adds entries using SASL EXTERNAL over the local LDAPI socket.
-Y EXTERNAL
: Uses the EXTERNAL SASL mechanism (local identity).
-H ldapi:///
: Targets the local LDAP IPC endpoint.
-f <file.ldif>
: Reads LDIF content from a file.
ldapadd -x -D <binddn> -W -f <file.ldif>
: Adds entries using a simple bind as a specified DN.
-x
: Uses simple authentication (non-SASL).
-D <binddn>
: Sets the bind DN (for example
cn=admin,dc=example,dc=com
).
-W
: Prompts for the bind password.
-f <file.ldif>
: Reads LDIF content from a file.
ldapsearch -x -LLL -b <baseDN>
: Queries entries under a base DN with clean output formatting.
-x
: Uses simple authentication (bindless by default if no
-D
is provided).
-LLL
: Produces simplified output (suppresses comments and version lines).
-b <baseDN>
: Sets the search base (for example
dc=example,dc=com
).