Remove an OU from OpenLDAP command line

Remove an OU from OpenLDAP command line

Remove an OU from OpenLDAP command line

In this example we have added the OU SkyNet, however since then, SkyNet has become self-aware and we need to remove it from the LDAP database before the real problems start. Let’s login, and su to root

Root shell prompt on the ldapdemo OpenLDAP server

from here change to the temp directory to manipulate the LDAP database

cd /tmp on the LDAP server

dump the LDAP database to file

ldapsearch -x > ldapdb to dump the LDAP directory to a file

vi the dump

vi ldapdb to open the LDAP dump

locate SkyNet

LDAP dump entry dn: ou=SkyNet,dc=mydomain,dc=local, objectClass organizationalUnit

from here do a ctrl+c and then a :set nu

vi command :set nu to show line numbers

this should show us the line numbers

Same screenshot: vi :set nu command

from here we want to write line 127 to a file named “SkyNet-Terminated”

Same :set nu screenshot repeated under the write-line-127 step

vi the File

vi SkyNet-Terminated to edit the delete LDIF file

here’s the syntax to delete the OU

LDIF dn: ou=SkyNet,dc=mydomain,dc=local with changetype:delete

run this command to process the change

ldapmodify -x -D cn=admin,dc=mydomain,dc=local -W -f SkyNet-Terminated

deleted!

ldapmodify output: deleting entry ou=SkyNet,dc=mydomain,dc=local

however, Given that it’s SkyNet, we had better make sure that it’s Actually gone from the database. Do another Dump

Same screenshot: ldapmodify deleting entry ou=SkyNet output

from here vi the dump

Same ldapmodify deleting entry screenshot repeated under the vi the dump step

from here we can search for SkyNet

vi search result E486: Pattern not found: SkyNet, confirming the OU is gone

cool, SkyNet has been exterminated!

That’s it!

Hosted Linux Servers at www.zwiegnet.com/go

Related guides: Add an OU to OpenLDAP command line | Remove user from openLDAP command line

Leave a Reply

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