OpenLDAP on AlmaLinux series, part 2. Part 1 installed slapd and configured cn=config. This part adds users and groups with LDIF (posixAccount/posixGroup). Part 3 adds TLS/LDAPS, part 4 covers replication with syncrepl and part 5 joins Linux clients with SSSD.
A freshly installed OpenLDAP server holds nothing but a base entry and two empty containers. Before any Linux host can log users in from the directory, it needs accounts and groups that carry POSIX attributes: a login name, a numeric UID and GID, a home directory and a shell. Those attributes come from the RFC 2307 nis schema, which you loaded in part 1 together with cosine and inetorgperson.
In this guide you plan UID and GID ranges, write LDIF files for inetOrgPerson + posixAccount + shadowAccount users and posixGroup groups, hash passwords with slappasswd, add the entries with ldapadd, change them with ldapmodify, set passwords with ldappasswd, create a read-only bind account for SSSD, and verify everything with ldapsearch and ldapwhoami. An optional section adds DN-based groupOfNames groups with a dynamic memberOf attribute for applications.
Every LDIF file, command and error message below was run against the same EL10 build as part 1: slapd 2.6.13 from EPEL 10 with the AlmaLinux 10 openldap-clients 2.6.13 tools. Object class requirements were checked against the nis, core and inetorgperson schema files shipped in the package, and the overlay details against the slapo-dynlist(5) man page.
Applies to: AlmaLinux 10.x with openldap-servers 2.6 from EPEL 10, set up as in part 1. The LDIF and client commands are identical on RHEL 10, Rocky Linux 10, Oracle Linux 10 and any other OpenLDAP 2.5/2.6 server that has the cosine, nis and inetorgperson schemas loaded.
Lab layout
| Host | IP | Role |
|---|---|---|
ldap1.example.lan | 192.168.1.70 | OpenLDAP provider from part 1 (all commands in this part run here) |
client1.example.lan | 192.168.1.71 | Test client with openldap-clients; becomes an SSSD client in part 5 |
ldap2.example.lan | 192.168.1.72 | Reserved for replication in part 4 |
| Setting | Value used here |
|---|---|
| Base DN (suffix) | dc=example,dc=lan |
| Directory administrator (root DN) | cn=admin,dc=example,dc=lan |
| Users | ou=People,dc=example,dc=lan (RDN uid=) |
| Groups | ou=Groups,dc=example,dc=lan (RDN cn=) |
| Service/bind accounts | ou=Services,dc=example,dc=lan (new in this part) |
| Data database | olcDatabase={2}mdb,cn=config |
| Working directory for LDIF files | /root/ldap (run the commands as root, e.g. after sudo -i) |
Prerequisites
- The server from part 1: slapd running, suffix
dc=example,dc=lan, root DNcn=admin,dc=example,dc=lan, and the base entry plusou=Peopleandou=Groupscreated. - The
cosine,nisandinetorgpersonschemas loaded (step 5 of part 1). Withoutnisthere is noposixAccount,posixGrouporshadowAccount. /etc/openldap/ldap.confwithBASE dc=example,dc=lanandURI ldap://ldap1.example.lan, so the commands below can omit-Hand-b.- The
openldap-clientspackage (it providesldapadd,ldapmodify,ldappasswd,ldapsearch,ldapwhoami) andopenldap-serversforslappasswd.
A quick check that the schemas and containers are in place:
sudo ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn=schema,cn=config dn
ldapsearch -x -LLL -D cn=admin,dc=example,dc=lan -W -s one dn
dn: cn=schema,cn=config
dn: cn={0}core,cn=schema,cn=config
dn: cn={1}cosine,cn=schema,cn=config
dn: cn={2}nis,cn=schema,cn=config
dn: cn={3}inetorgperson,cn=schema,cn=config
Enter LDAP Password:
dn: ou=People,dc=example,dc=lan
dn: ou=Groups,dc=example,dc=lan
Plan the uidNumber and gidNumber ranges first
LDAP users end up next to local accounts in /etc/passwd, so their numeric IDs must never collide with IDs that a client allocates on its own. On AlmaLinux 10, /etc/login.defs from shadow-utils ships these defaults:
grep -E '^(UID|GID|SYS_UID|SUB_UID)_(MIN|MAX)' /etc/login.defs
UID_MIN 1000
UID_MAX 60000
SYS_UID_MIN 201
SYS_UID_MAX 999
SUB_UID_MIN 524288
SUB_UID_MAX 600100000
| Range | Used by | Use for LDAP? |
|---|---|---|
| 0 to 999 | root and system accounts (SYS_UID_*) | No |
| 1000 to about 9999 | Local users created with useradd (it takes the next free ID above 1000) | No |
| 10000 to 14999 | LDAP user accounts and their private groups (this guide) | Yes |
| 15000 to 19999 | LDAP shared groups (this guide) | Yes |
| 60001 to 65535 | systemd-homed, systemd DynamicUser= (61184 to 65519) and nobody (65534) | No |
| 524288 and up | Subordinate UIDs/GIDs for rootless Podman (/etc/subuid, /etc/subgid) | No |
A few rules that save trouble later:
- Give each user a user private group with the same number (
uidNumber: 10001,gidNumber: 10001, groupcn=jdoe). That matches the RHEL default for local users and keepsumask 002collaboration safe. - Keep shared groups in their own block (15000 and up here), so a gidNumber tells you at a glance whether it is a private or a shared group.
- Never reuse a number after deleting an account. Files on disk still carry the old UID, and the next user would inherit them.
- If you want to make collisions impossible, lower
UID_MAX/GID_MAXin/etc/login.defson the clients to 9999. Part 5 also setsmin_id = 10000in SSSD.
To find the highest number already in use before you add an account (any bound identity can read these attributes with the ACLs from part 1):
ldapsearch -x -LLL -D cn=admin,dc=example,dc=lan -W -b ou=People,dc=example,dc=lan \
"(objectClass=posixAccount)" uidNumber | awk '/^uidNumber:/ {print $2}' | sort -n | tail -1
ldapsearch -x -LLL -D cn=admin,dc=example,dc=lan -W -b ou=Groups,dc=example,dc=lan \
"(objectClass=posixGroup)" gidNumber | awk '/^gidNumber:/ {print $2}' | sort -n | tail -1
LDAP does not enforce unique numbers by itself. Two entries with uidNumber: 10002 are perfectly valid to slapd, and the clients will treat them as the same user. Always check with a filter such as "(|(uidNumber=10002)(gidNumber=10002))" before you add an entry. The unique overlay (slapo-unique(5)) can enforce unique values server-side if you want slapd to refuse duplicates.
Which object classes a Linux account needs
Every entry needs exactly one structural object class chain, plus any number of auxiliary classes that add attributes. These are the requirements as defined in the schema files that ship with openldap-servers:
| Object class | Type (schema) | Required (MUST) | Useful optional (MAY) |
|---|---|---|---|
inetOrgPerson | Structural, inherits organizationalPerson and person (inetorgperson, core) | cn, sn | givenName, displayName, mail, uid, telephoneNumber, title |
posixAccount | Auxiliary (nis) | cn, uid, uidNumber, gidNumber, homeDirectory | userPassword, loginShell, gecos, description |
shadowAccount | Auxiliary (nis) | uid | shadowLastChange, shadowMin, shadowMax, shadowWarning, shadowInactive, shadowExpire |
posixGroup | Structural (nis) | cn, gidNumber | memberUid, description |
groupOfNames | Structural (core) | cn, member (at least one DN) | description, owner |
organizationalRole + simpleSecurityObject | Structural + auxiliary (core) | cn; userPassword | description |
Two consequences of that table. First, posixAccount and shadowAccount are auxiliary, so they must ride on a structural class such as inetOrgPerson (which also gives you mail, givenName and friends for address books and web applications). Second, the OpenLDAP nis schema defines posixGroup as structural, so you cannot combine it with groupOfNames in one entry. Linux group membership uses memberUid (a login name), applications that want DNs use groupOfNames (optional step 8).
Step 1: Create a container for service accounts
Bind accounts for SSSD, web applications or monitoring do not belong among the people. Give them their own OU:
cat > /root/ldap/20-services-ou.ldif <<'EOF'
dn: ou=Services,dc=example,dc=lan
objectClass: organizationalUnit
ou: Services
description: Service and bind accounts
EOF
ldapadd -x -D cn=admin,dc=example,dc=lan -W -f /root/ldap/20-services-ou.ldif
Enter LDAP Password:
adding new entry "ou=Services,dc=example,dc=lan"
Step 2: Hash the initial passwords with slappasswd
If you put a plain text userPassword into an LDIF file, slapd stores it exactly as given, in clear text. Hash it first. slappasswd prompts twice and prints an RFC 2307 value with a salted SHA-1 ({SSHA}) hash, which is the default scheme:
slappasswd
New password:
Re-enter new password:
{SSHA}bfG9hg++y4XYNj2V1qyjBnaoyBfa6z9M
Run it once per account (jdoe, asmith and the SSSD bind account) and copy each output into the LDIF files below. The same password gives a different hash every time because of the random salt. For a stronger, slower scheme you can generate SHA-512 crypt hashes with slappasswd -h {CRYPT} -c '$6$%.16s'; slapd verifies {CRYPT} values through the system crypt(3) library. Treat the files as secrets either way and chmod 600 them.
Step 3: Add the groups (posixGroup)
Add the groups before the users. It is not required by LDAP (a gidNumber is just a number), but it means the primary group exists the moment a user can log in. The file creates one private group per user and two shared groups. Membership in a posixGroup is a list of memberUid values holding login names, not DNs:
cat > /root/ldap/21-groups.ldif <<'EOF'
dn: cn=jdoe,ou=Groups,dc=example,dc=lan
objectClass: posixGroup
cn: jdoe
gidNumber: 10001
description: Private group for jdoe
dn: cn=asmith,ou=Groups,dc=example,dc=lan
objectClass: posixGroup
cn: asmith
gidNumber: 10002
description: Private group for asmith
dn: cn=sysadmins,ou=Groups,dc=example,dc=lan
objectClass: posixGroup
cn: sysadmins
gidNumber: 15001
description: Linux administrators
memberUid: jdoe
dn: cn=developers,ou=Groups,dc=example,dc=lan
objectClass: posixGroup
cn: developers
gidNumber: 15002
description: Application developers
memberUid: jdoe
memberUid: asmith
EOF
ldapadd -x -D cn=admin,dc=example,dc=lan -W -f /root/ldap/21-groups.ldif
Enter LDAP Password:
adding new entry "cn=jdoe,ou=Groups,dc=example,dc=lan"
adding new entry "cn=asmith,ou=Groups,dc=example,dc=lan"
adding new entry "cn=sysadmins,ou=Groups,dc=example,dc=lan"
adding new entry "cn=developers,ou=Groups,dc=example,dc=lan"
A user’s primary group comes from the gidNumber in the user entry, so you do not list jdoe as a memberUid of cn=jdoe. memberUid is only for supplementary groups.
Step 4: Add the users (inetOrgPerson + posixAccount + shadowAccount)
shadowLastChange counts days since 1 January 1970, the same unit as the third field of /etc/shadow. Compute today’s value:
echo $(( $(date +%s) / 86400 ))
20777
Now the user file. Replace the userPassword values with your own slappasswd output from step 2:
cat > /root/ldap/22-users.ldif <<'EOF'
dn: uid=jdoe,ou=People,dc=example,dc=lan
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
uid: jdoe
cn: John Doe
sn: Doe
givenName: John
displayName: John Doe
mail: jdoe@example.lan
uidNumber: 10001
gidNumber: 10001
homeDirectory: /home/jdoe
loginShell: /bin/bash
gecos: John Doe
userPassword: {SSHA}bfG9hg++y4XYNj2V1qyjBnaoyBfa6z9M
shadowLastChange: 20777
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
dn: uid=asmith,ou=People,dc=example,dc=lan
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
uid: asmith
cn: Alice Smith
sn: Smith
givenName: Alice
displayName: Alice Smith
mail: asmith@example.lan
uidNumber: 10002
gidNumber: 10002
homeDirectory: /home/asmith
loginShell: /bin/bash
gecos: Alice Smith
userPassword: {SSHA}REPLACE-WITH-YOUR-SLAPPASSWD-OUTPUT
shadowLastChange: 20777
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
EOF
chmod 600 /root/ldap/22-users.ldif
ldapadd -x -D cn=admin,dc=example,dc=lan -W -f /root/ldap/22-users.ldif
Enter LDAP Password:
adding new entry "uid=jdoe,ou=People,dc=example,dc=lan"
adding new entry "uid=asmith,ou=People,dc=example,dc=lan"
Notes on the attributes:
uidin the RDN is the login name. Keep it lowercase and free of spaces, because that is what users type at the login prompt and whatmemberUidrefers to.cnis required twice over (bypersonandposixAccount) but one value satisfies both.gecosis what SSSD shows as the comment field ingetent passwd.homeDirectoryis only a path. The directory itself is created on the client at first login (bypam_mkhomedir/oddjob-mkhomedir, part 5) or by an automounter.- The
shadow*values mean: no minimum age, no forced expiry (99999 days), warn 7 days before expiry. Clients only enforce them when SSSD usesldap_pwd_policy = shadow(part 5). - An LDIF with a hash is still sensitive: an offline dictionary attack against
{SSHA}is cheap. Delete or lock down the files once the entries exist.
Step 5: Set and change passwords with ldappasswd
ldappasswd uses the LDAP Password Modify extended operation (RFC 3062). The client sends the new password and slapd hashes it with its configured scheme (olcPasswordHash, {SSHA} unless you change it), so you never have to handle hashes by hand. This is the normal way to reset a password.
Reset a user password as the administrator
ldappasswd -x -D cn=admin,dc=example,dc=lan -W -S uid=jdoe,ou=People,dc=example,dc=lan
-S prompts for the new password twice and -W for the admin password. Without -S or -s, slapd generates a random password and prints it, which is handy for a temporary first password:
ldappasswd -x -D cn=admin,dc=example,dc=lan -W uid=asmith,ou=People,dc=example,dc=lan
Enter LDAP Password:
New password: BGwvGJLc
Let a user change their own password
The ACL from part 1 (to attrs=userPassword by self write) allows this. The user binds with their own DN; -A asks for the old password, -S for the new one, and with no target DN the operation applies to the bound identity:
ldappasswd -x -D uid=jdoe,ou=People,dc=example,dc=lan -W -A -S
Check the result with a bind as the user:
ldapwhoami -x -D uid=jdoe,ou=People,dc=example,dc=lan -W
Enter LDAP Password:
dn:uid=jdoe,ou=People,dc=example,dc=lan
Two things ldappasswd does not do. It does not update shadowLastChange, so if you enforce shadow aging, update that attribute in the same maintenance step (or let users change passwords through SSSD/PAM, which writes it). And a normal user who targets another DN gets Result: Insufficient access (50), which is exactly what you want.
Step 6: Change entries with ldapmodify
ldapmodify reads change records. Each record names a DN, a changetype, and one or more add:, replace: or delete: blocks separated by a line containing a single -. All blocks in one record are applied atomically. This file adds asmith to the sysadmins group and updates three attributes of her account in one go:
cat > /root/ldap/30-modify.ldif <<'EOF'
dn: cn=sysadmins,ou=Groups,dc=example,dc=lan
changetype: modify
add: memberUid
memberUid: asmith
dn: uid=asmith,ou=People,dc=example,dc=lan
changetype: modify
replace: loginShell
loginShell: /bin/zsh
-
add: telephoneNumber
telephoneNumber: +1 555 0102
-
replace: title
title: Senior Developer
EOF
ldapmodify -x -D cn=admin,dc=example,dc=lan -W -f /root/ldap/30-modify.ldif
Enter LDAP Password:
modifying entry "cn=sysadmins,ou=Groups,dc=example,dc=lan"
modifying entry "uid=asmith,ou=People,dc=example,dc=lan"
add:adds values and fails withType or value exists (20)if that exact value is already there.replace:sets the attribute to exactly the listed values, creating it if needed (titledid not exist before). Areplace:with no values removes the attribute.delete:with a value removes only that value; without a value it removes the whole attribute.
To take a user out of a supplementary group, delete just that memberUid value:
cat > /root/ldap/31-remove-member.ldif <<'EOF'
dn: cn=sysadmins,ou=Groups,dc=example,dc=lan
changetype: modify
delete: memberUid
memberUid: asmith
EOF
ldapmodify -x -D cn=admin,dc=example,dc=lan -W -f /root/ldap/31-remove-member.ldif
For one-off changes you can also pipe the record straight in, which is useful in scripts:
ldapmodify -x -D cn=admin,dc=example,dc=lan -W <<'EOF'
dn: uid=jdoe,ou=People,dc=example,dc=lan
changetype: modify
replace: mail
mail: john.doe@example.lan
EOF
Users cannot change their own loginShell or mail with the part 1 ACLs (they only have write on userPassword and shadowLastChange); they get Insufficient access (50). To remove an account completely use ldapdelete -x -D cn=admin,dc=example,dc=lan -W uid=USER,ou=People,dc=example,dc=lan, and remember the private group and any memberUid values, which are separate entries and values that LDAP will not clean up for you.
Step 7: Create a read-only bind account for SSSD
The ACLs from part 1 hide everything from anonymous clients, so SSSD on the Linux clients (part 5) needs an identity to search with. Give it a dedicated, unprivileged account instead of the root DN. organizationalRole plus simpleSecurityObject is the standard pair for a non-person entry with a password:
slappasswd
cat > /root/ldap/23-sssd-bind.ldif <<'EOF'
dn: cn=sssd-bind,ou=Services,dc=example,dc=lan
objectClass: organizationalRole
objectClass: simpleSecurityObject
cn: sssd-bind
description: Read-only bind account for SSSD on Linux clients
userPassword: {SSHA}REPLACE-WITH-YOUR-SLAPPASSWD-OUTPUT
EOF
chmod 600 /root/ldap/23-sssd-bind.ldif
ldapadd -x -D cn=admin,dc=example,dc=lan -W -f /root/ldap/23-sssd-bind.ldif
No ACL change is needed: to * by users read already lets any bound identity read accounts and groups, while to attrs=userPassword ... by * none keeps the hashes out of reach. Prove both from client1:
ldapwhoami -x -H ldap://ldap1.example.lan -D cn=sssd-bind,ou=Services,dc=example,dc=lan -W
ldapsearch -x -LLL -H ldap://ldap1.example.lan -D cn=sssd-bind,ou=Services,dc=example,dc=lan -W \
"(uid=jdoe)" uid uidNumber gidNumber homeDirectory loginShell userPassword
Enter LDAP Password:
dn:cn=sssd-bind,ou=Services,dc=example,dc=lan
Enter LDAP Password:
dn: uid=jdoe,ou=People,dc=example,dc=lan
uid: jdoe
uidNumber: 10001
gidNumber: 10001
homeDirectory: /home/jdoe
loginShell: /bin/bash
userPassword was requested but not returned, and an attempt to modify anything as sssd-bind fails with Insufficient access (50). Until part 3 enables TLS, this bind password crosses the network in clear text, so keep testing on a trusted lab network and do not reuse the password anywhere.
Step 8 (optional): groupOfNames and a dynamic memberOf
Many applications (web apps, VPNs, Jenkins, Grafana) prefer groups whose members are DNs and like to ask “which groups is this user in?” with a memberOf attribute on the user entry. In OpenLDAP 2.5 and 2.6 that attribute is best generated by the dynlist overlay; its man page states that the dynamic memberOf feature can fully replace the older memberof overlay. Unlike memberof, nothing is written to the user entries, so there is nothing to get out of sync.
dynlist is a loadable module and needs the dyngroup schema for its groupOfURLs/memberURL definition. The EPEL package configures no modules out of the box, so create the module list entry first (ldapi:/// as root, like all cn=config changes):
cat > /root/ldap/40-dynlist-module.ldif <<'EOF'
dn: cn=module{0},cn=config
objectClass: olcModuleList
cn: module{0}
olcModulePath: /usr/lib64/openldap
olcModuleLoad: dynlist.la
EOF
cat > /root/ldap/41-dynlist-overlay.ldif <<'EOF'
dn: olcOverlay=dynlist,olcDatabase={2}mdb,cn=config
objectClass: olcOverlayConfig
objectClass: olcDynListConfig
olcOverlay: dynlist
olcDynListAttrSet: groupOfURLs memberURL member+memberOf@groupOfNames
EOF
sudo ldapadd -Q -Y EXTERNAL -H ldapi:/// -f /root/ldap/40-dynlist-module.ldif
sudo ldapadd -Q -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/dyngroup.ldif
sudo ldapadd -Q -Y EXTERNAL -H ldapi:/// -f /root/ldap/41-dynlist-overlay.ldif
adding new entry "cn=module{0},cn=config"
adding new entry "cn=dyngroup,cn=schema,cn=config"
adding new entry "olcOverlay=dynlist,olcDatabase={2}mdb,cn=config"
If cn=module{0},cn=config already exists on your server (for example from another overlay), add olcModuleLoad: dynlist.la to it with ldapmodify instead. Part 4 (syncprov) and part 6 (ppolicy) load their modules into the same entry. The @groupOfNames suffix tells dynlist to include static groupOfNames groups in memberOf, not only dynamic groupOfURLs ones.
Now add a DN-based group and query it:
cat > /root/ldap/42-vpn-users.ldif <<'EOF'
dn: cn=vpn-users,ou=Groups,dc=example,dc=lan
objectClass: groupOfNames
cn: vpn-users
description: Allowed to use the VPN (DN-based group for applications)
member: uid=jdoe,ou=People,dc=example,dc=lan
member: uid=asmith,ou=People,dc=example,dc=lan
EOF
ldapadd -x -D cn=admin,dc=example,dc=lan -W -f /root/ldap/42-vpn-users.ldif
ldapsearch -x -LLL -D cn=sssd-bind,ou=Services,dc=example,dc=lan -W "(uid=jdoe)" memberOf
ldapsearch -x -LLL -D cn=sssd-bind,ou=Services,dc=example,dc=lan -W \
"(memberOf=cn=vpn-users,ou=Groups,dc=example,dc=lan)" dn
dn: uid=jdoe,ou=People,dc=example,dc=lan
memberOf: cn=vpn-users,ou=Groups,dc=example,dc=lan
dn: uid=jdoe,ou=People,dc=example,dc=lan
dn: uid=asmith,ou=People,dc=example,dc=lan
memberOf is operational, so it only shows up when you ask for it by name or with +; a plain ldapsearch ... "(uid=jdoe)" does not list it. A groupOfNames must always have at least one member, so removing the last member fails with an object class violation; delete the group or add a placeholder member instead. Linux logins keep using the posixGroup entries.
Verification
Look at the whole tree as the bind account. This is what a client will see:
ldapsearch -x -LLL -D cn=sssd-bind,ou=Services,dc=example,dc=lan -W dn
dn: dc=example,dc=lan
dn: ou=People,dc=example,dc=lan
dn: ou=Groups,dc=example,dc=lan
dn: ou=Services,dc=example,dc=lan
dn: cn=jdoe,ou=Groups,dc=example,dc=lan
dn: cn=asmith,ou=Groups,dc=example,dc=lan
dn: cn=sysadmins,ou=Groups,dc=example,dc=lan
dn: cn=developers,ou=Groups,dc=example,dc=lan
dn: uid=jdoe,ou=People,dc=example,dc=lan
dn: uid=asmith,ou=People,dc=example,dc=lan
dn: cn=sssd-bind,ou=Services,dc=example,dc=lan
dn: cn=vpn-users,ou=Groups,dc=example,dc=lan
The POSIX groups and their members, in the shape getent group will show them later:
ldapsearch -x -LLL -D cn=sssd-bind,ou=Services,dc=example,dc=lan -W \
-b ou=Groups,dc=example,dc=lan "(objectClass=posixGroup)" cn gidNumber memberUid
dn: cn=jdoe,ou=Groups,dc=example,dc=lan
cn: jdoe
gidNumber: 10001
dn: cn=asmith,ou=Groups,dc=example,dc=lan
cn: asmith
gidNumber: 10002
dn: cn=sysadmins,ou=Groups,dc=example,dc=lan
cn: sysadmins
gidNumber: 15001
memberUid: jdoe
dn: cn=developers,ou=Groups,dc=example,dc=lan
cn: developers
gidNumber: 15002
memberUid: jdoe
memberUid: asmith
Which supplementary groups is jdoe in? With RFC 2307 groups, SSSD resolves supplementary groups with essentially this search:
ldapsearch -x -LLL -D cn=sssd-bind,ou=Services,dc=example,dc=lan -W \
-b ou=Groups,dc=example,dc=lan "(&(objectClass=posixGroup)(memberUid=jdoe))" cn gidNumber
A quick true/false test for one membership is ldapcompare. It prints TRUE or FALSE, and its exit status is 6 for true and 5 for false (not 0), which matters in scripts:
ldapcompare -x -D cn=sssd-bind,ou=Services,dc=example,dc=lan -W \
cn=developers,ou=Groups,dc=example,dc=lan memberUid:jdoe
As the administrator you can confirm the password is stored hashed. userPassword has octet string syntax, so ldapsearch prints it base64 encoded (note the double colon):
ldapsearch -x -LLL -D cn=admin,dc=example,dc=lan -W "(uid=jdoe)" userPassword
echo 'e1NTSEF9M1hYY00vdzNCR0JPZkh1Q0Z2RnFEeXZ0Z2Q0TFRrUXg=' | base64 -d; echo
dn: uid=jdoe,ou=People,dc=example,dc=lan
userPassword:: e1NTSEF9M1hYY00vdzNCR0JPZkh1Q0Z2RnFEeXZ0Z2Q0TFRrUXg=
{SSHA}3XXcM/w3BGBOfHuCFvFqDyvtgd4LTkQx
If that decodes to something without a {SCHEME} prefix, the password is stored in clear text: reset it with ldappasswd, which stores a hash. Finally, add the new entries to your backup:
slapcat -b dc=example,dc=lan -l /root/ldap-backup/data-$(date +%F).ldif
Troubleshooting
All of these messages were reproduced on slapd 2.6.13. The number in brackets is the LDAP result code, which is also the exit status of the client tool.
| Symptom or error | Likely cause | Fix |
|---|---|---|
ldap_bind: Invalid credentials (49) | Wrong password, or a bind DN that does not exist (slapd returns 49 for both, on purpose), or the entry has no userPassword | Check the DN with ldapsearch as admin; reset with ldappasswd; for the root DN check olcRootPW (part 1) |
ldap_bind: Invalid DN syntax (34) | -D admin instead of a full DN | Use -D cn=admin,dc=example,dc=lan |
Object class violation (65), object class 'inetOrgPerson' requires attribute 'sn' | A MUST attribute is missing (same pattern for posixAccount and gidNumber, uidNumber, homeDirectory) | Add the attribute; see the object class table above |
Object class violation (65), no structural object class provided | Only auxiliary classes (posixAccount, shadowAccount) listed | Add objectClass: inetOrgPerson (or account) |
Object class violation (65), invalid structural object class chain (posixGroup/groupOfNames) | Two unrelated structural classes in one entry | Keep posixGroup and groupOfNames as separate entries |
Object class violation (65), attribute 'loginShell' not allowed | The attribute belongs to an object class the entry does not have | Add objectClass: posixAccount (with its MUST attributes) or drop the attribute |
No such object (32) with matched DN: dc=example,dc=lan on add | The parent (e.g. ou=Staff) does not exist; matched DN shows the deepest existing ancestor | Create the OU first, or fix the DN typo |
No such object (32) on a search that should match | Anonymous search (the part 1 ACLs hide everything), or a wrong base; see result 32 No such object with ldapsearch -x | Bind with -D ... -W; check BASE in /etc/openldap/ldap.conf |
ldap_add: Already exists (68) | The entry was added on an earlier run (ldapadd stops at the first error) | Use ldapmodify to change it, or ldapadd -c to continue past existing entries when re-running a file |
Type or value exists (20), modify/add: memberUid: value #0 already exists | Adding a value that is already present | Nothing to do, or use replace: |
No such attribute (16), modify/delete: memberUid: no such value | Deleting a value that is not there (often a case or spelling difference) | Search the entry first and copy the exact value |
Invalid syntax (21), objectClass: value #1 invalid per syntax | Unknown object class: a typo (posixAccountt), a trailing space, or the nis/inetorgperson schema is not loaded | Fix the spelling or trailing whitespace; check -b cn=schema,cn=config dn and load cosine, nis, inetorgperson in that order |
Invalid syntax (21), uidNumber: value #0 invalid per syntax | A non-integer in uidNumber/gidNumber | Use digits only |
Undefined attribute type (17), sshPublicKey: attribute type undefined | The attribute comes from a schema the server does not have (here the OpenSSH-LPK schema) | Load the schema into cn=config first, or remove the attribute |
Insufficient access (50) | A user or sssd-bind trying to write; a user running ldappasswd on another DN | Do it as the root DN, or extend the ACLs deliberately (part 6) |
Can't contact LDAP server (-1) | slapd down, firewall, or wrong URI in ldap.conf | systemctl status slapd, firewall-cmd --list-services, try -H ldap://192.168.1.70 |
Two users show the same name in ls -l, or a new user owns old files | Duplicate or reused uidNumber | Search for the number before adding; never recycle IDs |
| Password appears in clear text when decoded | userPassword was added unhashed in LDIF | Reset with ldappasswd; hash with slappasswd in future LDIF |
Two LDIF pitfalls that do not always produce an obvious error: a continuation line starts with one space that is removed when the lines are joined (so a long value split across lines must not lose or gain characters at the break), and a trailing space after a value is kept as part of the value. On objectClass it causes the Invalid syntax (21) above; on other attributes it is stored silently. A memberUid: bob with a trailing space comes back base64 encoded (memberUid:: Ym9iIA==) and clients receive bob , which is not the user bob. A :: on a value you expected to be plain text is the giveaway.
What is next
The directory now holds real accounts and groups with POSIX attributes, a password workflow and a read-only bind identity. Part 3 issues a certificate for ldap1.example.lan from a private CA and enables StartTLS and LDAPS, so these passwords stop crossing the network in clear text. Part 4 replicates the tree to ldap2, and part 5 points SSSD on client1 at both servers with the sssd-bind account, so getent passwd jdoe and ssh jdoe@client1 work.
Next: part 3, Configure OpenLDAP TLS and LDAPS on AlmaLinux 10 (StartTLS, Private CA, cn=config).
