Ldap – Automatically create home directory on NFS after LDAP login

autofsldapnfspampam-ldap

My current situation is that I can successfully authenticate using ldap and pam, I also succeeded to use pam_mkdir to autocreate home directories in the /home filesystem.

What now I'm trying to achieve is to autocreate the same home directories but on an automounted nfs export. The automount works correctly and the homes root is correctly reachable. The aim is to avoid to create homes on the nfs manually.

I spent last two days lurking around, but I did not succeed to merge all the informations together.

The questions I still have:

  • could pam_mkdir create directories over nfs?
  • if the mounted homes path is not standard (e.g. homes are mounted to /mnt/nfs/homes), how pam_mkdir can know that? Using a homeDirectory LDAP attribute?
  • Should I instead trigger the creation on the LDAP server after user creation?
  • Am I overthinking an actually simpler problem?

Best Answer

It's most likely that you're running into an NFS permissions issue. In a standard setup, NFS client machines are not trusted for root access on the NFS server; access by uid=0 is mapped to an unprivileged user (nfsnobody or similar). In order to create the home directory, pam_mkdir (which runs as root) would need to have permissions to the directory in which the user's homedir would be created (generally /home/), and when remapped to nfsnobody, this fails. You could disable this remapping option, but that's generally a bad idea; the better approach is to have a script that walks your LDAP directory and creates missing home directories on the NFS server directly.