I have an LDAP user who accesses a server based on having the appropriate LDAP host attribute via sssd. This user does not show up in /etc/passwd because he is not local. How do I modify his home dir location if he has already logged in and it was created in the default location? RHEL 6 Is it just usermod -d /new/location -m?

  • It says user not found in /etc/passwd when I try useradd but the user is reconized in LDAP and I cant add the user because it already exists. I believe my config is: files ldap. Dec 23 '13 at 20:44

This is actually shockingly easy. If your nsswitch is files ldap; just add an entry for them in /etc/passwd and modify whatever parameter you want. If they don't already exist in /etc/passwd, you could do getent passwd <username> | sed 's|/home/<username>|/home/remoteusers/<username>|g' >> /etc/passwd for instance to change their home directory from the root of /home to a subfolder of home called remoteusers. The caveat is that you cannot use useradd or usermod, you must edit the file with an editor.

  • This actually creates a new local user entry for them, it doesn't edit the original entry.
    – robbat2
    May 23 '15 at 3:18

I achieved this on Ubuntu 18.04 using OpenLDAP and SSSD by doing the following:

  • In the user's LDAP entry just modify the homeDirectory: /path/to/custom/home/username, you can check out ldapmodify for this
  • In the SSSD daemon configuration file sssd.conf, under [nss], add or edit the parameter override_homedir = /path/to/custom/home/%u

  • In the linux PAM common-session module add the following entry if you want to have the user's home directory created upon first login

    :~# tail -1 /etc/pam.d/common-session
    session    optional pam_mkhomedir.so skel=/etc/skel/ umask=077```
  • test by using su with a LDAP user and check that the user's home is created where necessary


I don't believe that RHEL's usermod (or any stock NSS tools) supports changing the contents of NSS. You will probably need to actually modify the contents of LDAP, then move his home directory. Possible tools for you: diradm (look at the v2 fork in Gentoo esp.), ldapvi, cpu, ldapscripts (might be debian-only)


I know this thread is old. However, I stumbled across it while attempting the same thing on CentOS 7. I imagine the process is the same. I needed to change several users directories from /home/USER to /home/ldap-users/USER.

First create an ldif file with the changes you want to make. I named mine changehomedirs.ldif. You may need to change your ou depending on what organizational unit you put your users in. I called mine People.

Then I wrote a script to essentially loop through each LDAP user one at a time and used sed to replace the word USER in the changehomedirs.ldif file to the current user in the loop and redirect the output to a temporary file named tmp.ldif.

Then I used the ldapmodify command to make the changes by using the -f option to read the desired changes from the tmp.ldif file. The example is in the screenshot below.

This is just a testing system so the password is not sensitive in nature.

Home dirs before LDAP modification

How to change a users home directory in LDAP

Home dirs after LDAP modification

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.