r/LinuxTeck • u/Expensive-Rice-2052 • 6h ago
Verify LDAP Users in Linux Using ldapsearch - 139
Question: How do I verify a user in LDAP/AD exists before adding them?
Try:ldapsearch -x -H ldap://ldap.example.com -b 'dc=example,dc=com' -D 'cn=admin,dc=example,dc=com' -W '(uid=jsmith)' cn mail
Info: Queries LDAP/AD directories for matching users.
Examples:
$ ldapsearch -x -H ldap://server -b 'dc=example,dc=com' '(objectclass=user)' cn mail # Query AD user entries
$ ldapwhoami -x -D 'cn=admin,dc=example,dc=com' -W # Verify bind credentials
$ ldapsearch -LLL ... # Output clean LDIF without comments
Note: Install via sudo apt install ldap-utils. Use LDAPS (`ldaps://` or port 636) or StartTLS instead of cleartext LDAP in production, match AD attributes like `sAMAccountName` or `userPrincipalName`, and check `getent passwd` to confirm NSS resolution.
Want to master Linux one command at a time?
Follow r/LinuxTeck - 1 practical Linux tip every day. For more #LinuxTips click here https://www.linuxteck.com/linux-tips/