Remove user from openLDAP command line

Remove user from openLDAP command line

Remove user from openLDAP command line

Let’s say our user “Shawn Dawn” was terminated from the company, for a number of reasons. Now it’s time to remove his user account from LDAP, what do we do?

login, and su to root

Root shell prompt on the ldapdemo OpenLDAP server

from here change to /tmp to manipulate the LDAP database

cd /tmp at the root prompt on ldapdemo

from here take a dump of the LDAP database

Same screenshot: cd /tmp, shown where the step says to dump the LDAP database

from here edit the ldap database

vi ldapdb to open the LDAP dump file

look for the account shawn

LDAP dump entry for shawn dawn: dn cn=shawn dawn,ou=people,dc=mydomain,dc=local, uid shawn, uidNumber 1001

here it is, now we need to get the line numbers with ctrl+c and then :set nu

shawn dawn entry in vi with line numbers 54-66 after :set nu

here’s how it looks

Same screenshot: shawn dawn entry with line numbers, dn on line 55

now we need to write his account to a file to modify

vi command :55 w! shawn to write the dn line to a file named shawn

here we are writing line 55 to a file named shawn

vi the file

vi shawn at the root prompt in /tmp

add the following lines, it should look as so:

shawn LDIF: dn cn=shawn dawn,ou=people,dc=mydomain,dc=local with changetype:delete

basically we are modifying LDAP to delete memberUid shawn

now we need to commit the change to the LDAP database

ldapmodify -x -D cn=admin,dc=mydomain,dc=local -W -f shawn typed to apply the delete

enter your LDAP admin password

ldapmodify output: Enter LDAP Password, deleting entry cn=shawn dawn,ou=people,dc=mydomain,dc=local

now shawn should be deleted, let’s make sure by re-dumping ldap

ldapsearch -x > ldapdb to re-dump the directory and confirm the deletion

vi the LDAP Database

vi ldapdb to search the new dump for shawn

in a search for shawn, pattern was not found!

vi error E486: Pattern not found: shawn, confirming the user was removed

at this point you should consider removing their home directory as well

we are done!

Hosted Linux servers at www.zwiegnet.com/go

Related guides: Remove user from a group OpenLDAP command line | Add User to LDAP command line

Leave a Reply

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