Gabriel Cretin
Gabriel Cretin

Reputation: 405

OpenLDAP associate existing users to an organization unit (OU)

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

Upvotes: 0

Views: 619

Answers (2)

EricLavault
EricLavault

Reputation: 16035

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"
    

Upvotes: 1

Gabriel Cretin
Gabriel Cretin

Reputation: 405

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

Upvotes: 1

Related Questions