The OS is Amazon Linux 2023. I am trying to use LDAP to do user/group management for all new users. I've installed openldap-servers, openldap-clients and nss-pam-ldapd packages. I've configured SSL on slapd and
ldapwhoami -x -H ldaps://myserver.mydomain.com
ldapwhoami -x -H ldapi:///
both return anonymous.
sudo ldapwhoami -H ldapi:///
returns dn:gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth.
I've set nsswitch.conf to:
passwd: ldap sss files
shadow: ldap files
group: ldap sss files
I've set nslcd.conf to:
uid root
gid root
uri ldapi:///
base dc=mydomain,dc=com
When I run:
sudo useradd -b /home balaguru1
it does not appear to add the user to the LDAP db. The files in /var/lib/ldap/ are unchanged. /etc/passwd is modified with the new user.
What am I missing?
The nsswitch interface is read-only – it doesn't have any add or modify operations that the name service modules could provide, and all such tools perform modifications directly to the backend.
For example, your
useradd
tool has been written specifically to update the local account database through /etc/passwd & /etc/shadow and nothing else. (Indeed it comes from the 'shadow' package which is solely for maintaining the passwd/shadow/group files.)You will need a different tool for LDAP account management.¹
¹ (I don't know of any that would be still maintained; I ended up more-or-less writing my own. A shell script around
ldapadd
would work.)Typical LDAP implementations are designed to have configurable schema; OpenLDAP ships with several traditional schema configs under
/etc/(open)ldap/schema
.You're looking for the
posixAccount
objectClass, which – as you've already found – is in thenis
schema file. However, it is an auxiliary class, and usually attached to aperson
orinetOrgPerson
object (from thecosine
schema in this case); although nothing stops you from attaching it to adevice
object or anapplicationProcess
object. (The latter is an OSI & X.500 relic but is somewhat fitting for representing e.g. a service that needs its own LDAP password and/or its own POSIX account.)Yes, and you'll have to create the "parent" entries before you can put anything underneath. If you just started with an empty database, you'll need to create even the toplevel entry corresponding to your database suffix (e.g.
dc=example,dc=org
as anobjectClass: domain
entry, oro=My Little Org
as anorganization
entry). Then create OUs asorganizationalUnit
objects – although it's not required to put users and groups under OUs; it's okay to create them under the toplevel entry; they can be moved into an OU later anyway.(Note that you only have to add parents up to the DB suffix – you do not need to add
dc=org
in this example.)Let's say you have a database entry configured like this:
This means you would need to create these entries (assuming you want the typical OU=Users kind of hierarchy):
Whereas if you had
olcSuffix: dc=example,dc=com
(AD-style), you would need to add:(If all programs support the "bind as app, search, bind as user" model, then whether to use
dn: cn=
ordn: uid=
for the user entry's DN is your choice. Most programs are fine with this, as it's what Active Directory does. But if some programs only support "bind asuid=%s,ou=Users,etc
according to a DN template" model, then you'll need to useuid=
.)