Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove all records from LDAP?

Is it possible to remove all entries from LDAP by one-line commend?

I tried:

ldapdelete -r 'cn=*,dc=domain,dc=com' -w

but it's not working. I have no better ideas;/

like image 904
ruan Avatar asked Jul 18 '17 08:07

ruan


People also ask

How do I delete all entries in LDAP?

Deleting multiple entries using an LDIF file You can generate a file of DNs that you would like to delete from the Directory Server. The following command searches for all entries in the ou=Accounting branch and returns the DNs of the subentries. Run the ldapdelete command with the file to delete the entries.

How do I completely remove LDAP from Ubuntu?

Here is the tutorial to learn how to uninstall ldap auth client with apt-get command. Step 1: Open a terminal with 'su' access and enter the command as shown below. Step 2: The command reads the package lists and proceeds with the uninstallation. Use 'apt-get autoremove' to remove them.

How do I delete a Ldif file?

2.2 LDIF Format for Deleting Entries. When deleting an entry, the LDIF file entry only needs the DN of the entry to be deleted and the changetype: delete directive. Use an empty line at the end of the entry as a separator.


1 Answers

ldapdelete is to remove specific DN, you can't use a wilcard.

There is no native "oneliner". You can execute a ldapsearch and provide the list of DN resulting from this search to the ldapdelete

Something like :

ldapsearch -LLL -s one -b "dc=domain,dc=com" "(cn=*)" dn | awk -F": " '$1~/^\s*dn/{print $2}' > listOfDNtoRemove.txt && ldapdelete -r -f listOfDNtoRemove.txt
  • -s one : this option on the ldapsearch is to retrieve only the first level child under the branch dc=domain,dc=com
  • -LLL : this option is to have LDIF format output
  • -r : this option is to recursively delete the previously first level branch found and their childs
  • awk -F": " '$1~/^\s*dn/{print $2}' : this awk is to print only the line starting by dn: and printing the value of the dn

NOTE : ldapdelete also reads the list of DN from the standard input, so you can pipe the ldapsearch results directly to the ldapdelete if you want to avoid the temporary file

like image 180
Esteban Avatar answered Sep 27 '22 18:09

Esteban