Change home directory of LDAP user command line

Change home directory of LDAP user command line

Change home directory of LDAP user command line

In this scenario, we are moving the home directory of a user to another location in LDAP. We are assuming at this point that the physical files/folders are in the new location, and that all we have to do is modify the LDAP home directory so they can login properly.

In this example, we are modifying the user “John” his home directory is presently /home/users/john, but management wants him to be in /home/john. Here’s the process

login, and su to root

Root shell prompt on the OpenLDAP server ldapdemo after su to root

from here change to the /tmp directory where we can modify the ldap database

Running ldapsearch -x > ldapdb in /tmp to dump the LDAP directory to a file

from here do a dump of the LDAP Database

Running ldapsearch -x > ldapdb to save the LDAP entries before editing John's account

now we need to vi the ldapdb

Running vi ldapdb to open the LDAP dump file

in this case, we are going to change “John’s” home directory, so locate the user John

John Smith's LDAP entry in the dump showing homeDirectory /home/users/john

found him, ok, now we need to set the line numbers to show up, hit ctrl+c and then :set nu

Typing :set nu in vi to turn on line numbers

now we can see the line numbers

LDAP dump in vi with line numbers, John Smith's dn on line 67

now we have to write line 67 for the user dn to file, hit ctrl +c and then type 67 w! John

Running vi John to open the file holding John's dn line

this obviously writes line 67 to a file named John. Quit out, and vi John

Running vi John to edit the LDIF change for John's home directory

setup the file as follows:

LDIF with changetype modify and replace homeDirectory set to /home/john

so as you can see we are changing John’s home directory from /home/users/john to /home/john

now we need to commit the change to the LDAP database, do so with the following command:

Running ldapmodify -x -D cn=admin,dc=mydomain,dc=local -W -f John to apply the change

enter your LDAP admin password, and you should see the following:

ldapmodify output modifying entry cn=John Smith,ou=people,dc=mydomain,dc=local

no errors, so now we need to double-check all worked properly in ldap by doing another dump

Running ldapsearch -x > ldapdb again to dump the directory after the change

from here vi the file

Running vi ldapdb to check John's updated LDAP entry

now as we can see on the final line, is that John’s home directory has changed!

John Smith's LDAP entry now showing homeDirectory /home/john

That’s it!

Hosted Linux Servers at www.zwiegnet.com/go

Related guides: Update LDAP account command line | Add User to LDAP command line

Leave a Reply

Your email address will not be published. Required fields are marked *