OpenLDAP associate existing users to an organization unit (OU)

298 Views Asked by At

I created an OpenLDAP server on Ubuntu 22.04, and created users but forgot to add them to a organizational unit (ou). How can I associate them all to an ou now ?
The actual server looks like this:

dn=company
    ou=Users
    uid=user1
    uid=user2
    uid=user3
    ...

What I would like is:

dn=company
    ou=Users
        uid=user1
        uid=user2
        uid=user3
        ...

Concretely, I would like to go from this:

uid=user1,dc=example,dc=fr

to this:

uid=user1,ou=Users,dc=example,dc=fr
2

There are 2 best solutions below

0
EricLavault On BEST ANSWER

Adding an ou attribute to the entry is one thing, moving the entry in the DIT is another thing. For the latter, you need to use the newsuperior directive.

  • Using ldapmodify -f with changetype: (modrdn|moddn) :

    dn: uid=user1,dc=example,dc=fr
    changetype: modrdn
    # rdn unchanged
    newrdn: uid=user1
    # deletes old entry
    deleteoldrdn: 1
    # adds to Users hierarchy
    newsuperior: ou=Users,dc=example,dc=com
    
  • Using ldapmodrdn -r -s <newsuperior> <dn> <newrdn> :

    ldapmodrdn -r -s "ou=Users,dc=example,dc=com" "uid=user1,dc=example,dc=fr" "uid=user1"
    
1
Gabriel Cretin On

Actually I just found an answer on my own. I simply did a LDIF file modify.ldif:

dn: uid=user1,dc=example,dc=fr
changetype: modify
add: ou
ou: Users

And then ldapmodify -x -D cn=admin,dc=example,dc=fr -W -f ./modify.ldif