Anyone who ran Solaris with an LDAP naming service remembers ldaplist: one short command to list users, groups, sudoers or automount maps from the directory, without writing an ldapsearch filter. Linux never had an equivalent. ldaplist for Linux is a new open-source C utility that brings that Solaris-style interface to OpenLDAP and Microsoft Active Directory, with Kerberos single sign-on by default.
Project on GitHub: azwieg103/ldaplist
What ldaplist does
ldaplist is a read-only LDAP listing tool. It talks to the directory directly through the OpenLDAP libldap library rather than shelling out to ldapsearch, and it prints results in formats admins already know. People come out as classic passwd-style lines:
uid:uidNumber:gidNumber:gecos:homeDirectory:loginShell
With -t you get a fixed-width, pipe-delimited table of uid, first name, last name, mail and mobile instead. It only searches. It never modifies directory data.
Features
- Written in C on top of OpenLDAP
libldap. LDAPv3, with both LDAP and LDAPS URIs. - Kerberos/GSSAPI single sign-on by default, using your existing credential cache. Simple bind is available with
-W,-wor-j. - Unprivileged auto-discovery from readable OpenLDAP client configuration, readable SSSD domain settings, Kerberos realm configuration, the host’s DNS domain and LDAP DNS SRV records.
- Searches below the base DN by matching object classes, rather than assuming every directory has Unix-style
ou=Peopleandou=Groupscontainers. - Separate selectors for People, SUDOers, Groups and automount, which you can combine in one run.
- Password-file support (
-j), which is safer than putting a password on the command line. - Optional named profiles in
/etc/ldaplist/profiles/NAME.conf. - AlmaLinux 10 x86_64 binary and source RPMs, published as GitHub Releases after CI passes.
Syntax and options
ldaplist [-dlv] [-h LDAP_server[:serverPort]] [-M domainName] [-N profileName] [-a authenticationMethod] [-P certifPath] [-D bindDN] [-w bindPassword] [-W] [-j passwdFile] [-t] [-p|-s|-g|-u|-y] [database [key]...]
| Option | Meaning |
|---|---|
-d | LDAP library diagnostics |
-l | Classic/long output (default) |
-v | Verbose connection and search diagnostics |
-h | LDAP host, optionally with port. Port 636 selects LDAPS |
-M | DNS domain (converted to a base DN) or an explicit base DN |
-N | Named profile from /etc/ldaplist/profiles/NAME.conf |
-a | kerberos (default), simple, bind, anonymous or gssapi |
-P | CA certificate file or directory. Verification is required |
-D | Bind DN |
-w | Bind password (visible in process arguments, so avoid it) |
-W | Prompt for the bind password without echo |
-j | Read the password from the first line of a file |
-t | Tab-separated People table |
-p / -s / -g / -u | Search People / SUDOers / Groups / automount |
-V, -? | Version, help |
Install ldaplist on AlmaLinux 10
From the RPM
Download the latest binary RPM from the releases page (releases follow the ldaplist-1.0.0-ZWIEGNET.N.el10 pattern) and install it with dnf. The package pulls in openldap, cyrus-sasl-lib, cyrus-sasl-gssapi and krb5-libs:
sudo dnf install ./ldaplist-1.0.0-ZWIEGNET.N.el10.x86_64.rpm
ldaplist -V
AlmaLinux 10 x86_64 is the primary target. RHEL 10, Rocky Linux 10, Oracle Linux 10 and CentOS Stream 10 are intended to work but aren’t individually tested.
From source
sudo dnf install -y gcc make openldap-devel cyrus-sasl-devel krb5-devel pkgconf-pkg-config
git clone https://github.com/azwieg103/ldaplist.git
cd ldaplist
make
make check
sudo make install
make install puts the binary in /usr/bin/ldaplist and the man page in /usr/share/man/man1/ldaplist.1. Set PREFIX to install somewhere else.
Kerberos single sign-on (the default)
If your workstation already gets Kerberos tickets, ldaplist uses them through SASL GSSAPI, with no password prompt and no extra flags:
kinit user@EXAMPLE.COM
klist
ldaplist -h ldap.example.com -M example.com -p
ldaplist -h ldap.example.com -M example.com -a gssapi -p -t
The LDAP server has to support GSSAPI, and DNS, time sync, the realm configuration and the ldap/ service principal all have to be right. If you’re setting that up from scratch, see Set Up an MIT Kerberos KDC on AlmaLinux 10 and Configure a Kerberos Client on AlmaLinux 10.
Simple bind to Active Directory or OpenLDAP
For a service account, use LDAPS and let ldaplist prompt for the password with -W:
ldaplist -h dc1.example.com:636 -M example.com \
-D 'CN=LDAP Reader,OU=Service Accounts,DC=example,DC=com' -W -p
Supplying -D with -W, -w or -j switches to simple bind automatically unless you set -a yourself. For scripts, keep the password in a mode-0600 file and pass it with -j:
install -m 0600 /dev/null "$HOME/.ldaplist.pass"
# add the password with an editor, then:
ldaplist -h dc1.example.com:636 -M example.com -D 'CN=LDAP Reader,OU=Service Accounts,DC=example,DC=com' -j "$HOME/.ldaplist.pass" -p
Don’t use -w on shared systems, because command-line arguments can show up in process listings and shell history.
Everyday examples
ldaplist -h ldap.example.com -M example.com -p -t # user table
ldaplist -h ldap.example.com -M example.com -s # sudoers
ldaplist -h ldap.example.com -M example.com -g # groups
ldaplist -h ldap.example.com -M example.com -u # automount maps
ldaplist -h ldap.example.com -M example.com passwd jdoe # one user
ldaplist -h ldap.example.com -M example.com groups engineering
ldaplist -h ldap.example.com -M example.com -p -s -g -u # everything
Those sudoers and automount listings pair well with Configure LDAP group for SUDO and Configure AutoMount CentOS 7.
Directory layouts and schema
Searches run recursively below the discovered base DN. People matches POSIX accounts and AD user objects. Groups matches POSIX groups and AD groups. SUDOers and automount match their schema object classes. To narrow a search to one subtree, set these environment variables to a relative RDN such as ou=UnixUsers:
export LDAPLIST_BASE_DN=dc=example,dc=com
export LDAPLIST_PEOPLE_OU=ou=UnixUsers
# also: LDAPLIST_SUDOERS_OU, LDAPLIST_GROUPS_OU, LDAPLIST_AUTOMOUNT_OU,
# LDAPLIST_DOMAIN, LDAPURI
- OpenLDAP: typically
inetOrgPersonplusposixAccountfor people,posixGroupfor groups,sudoRolefor sudoers andautomountMap/automountfor maps. New to OpenLDAP on EL10? Start with Install OpenLDAP Server on AlmaLinux 10 with cn=config. - Active Directory: often uses
CN=Usersor custom OUs, so set the OU overrides.givenName,sn,mailandmobileare read directly. The passwd fields (uidNumber,gidNumber,homeDirectory,loginShell) need RFC2307/Unix attributes or an equivalent mapping.
Profiles are optional key/value files with the keys server, port, domain, base_dn, auth, bind_dn and ca_file. Use one with -N NAME, and keep the file permissions tight.
Troubleshooting
- GSSAPI bind fails: check
klistfor a valid TGT, confirm the clock is in sync and make sure the server name you pass to-hmatches itsldap/principal. Add-vor-dfor diagnostics. - TLS errors on port 636: certificate verification is mandatory. Point
-Pat the right CA file or directory. OpenLDAP over TLS: Client Setup, StartTLS Testing and Troubleshooting covers the client side. - Empty results from AD: your users probably aren’t under the expected containers. Set
LDAPLIST_PEOPLE_OUand friends, or check that the bind account can read them. - Blank passwd fields: the entries have no RFC2307 attributes.
Current limitations
This is the initial 1.0.0 release. The project recommends testing against a non-production directory first, because AD schemas and OU layouts vary. Full AD member DN expansion and schema-specific output are listed as future enhancements.
License and source
ldaplist is licensed under the GNU GPL version 2 only (GPL-2.0-only). Get the source, man page and RPMs at github.com/azwieg103/ldaplist.
