Override users’ LDAP homeDirectory attribute when using nslcd and libnss-ldapd

When using LDAP authentication with PAM, by default the path for the users’ home directory is set based on the user objects’ homeDirectory attribute. If for any reason that home directory path is not correct for the given system, it is possible to override it for all LDAP users when using nslcd and libnss-ldapd.

A lot of random StackOwerflow and similar posts recommend periodically editing /etc/passwd with custom scripts or plugging custom scripts into PAM, which might kinda work, but this is a much cleaner solution.

The solution was tested on Ubuntu 20.04 and 22.04.

Steps required

  1. Make sure the nslcd and libnss-ldapd apt packages are installed and that apart from the home directory PAM, LDAP, NSLCD, etc. are working correctly
  2. In /etc/nslcd.conf add the following line to override the home path: map passwd homeDirectory "/custom/home/path/$uid"
    • $uid is the user’s uid attribute, other attributes are also possible in the override
  3. Restart the nslcd service with: systemctl restart nslcd.service

References