When managing LDAP directories, a common administrative task is adding existing users to existing groups. Unlike creating new groups with members, this operation requires modifying an existing group entry by updating its member
or uniqueMember
attribute (depending on your schema).
Before proceeding, ensure:
- You have write permissions to modify the group
- Both user and group DNs are correct
- Your LDAP server supports the operation
The most straightforward approach is using the ldapmodify
command with an LDIF file:
ldapmodify -x -D "cn=admin,dc=example,dc=com" -W -f add_user.ldif
Where add_user.ldif
contains:
dn: cn=vipb,ou=groups,dc=example,dc=com
changetype: modify
add: member
member: uid=fred,ou=people,dc=example,dc=com
For quick operations, you can pipe the LDIF directly:
ldapmodify -x -D "cn=admin,dc=example,dc=com" -W << EOF
dn: cn=vipb,ou=groups,dc=example,dc=com
changetype: modify
add: member
member: uid=fred,ou=people,dc=example,dc=com
EOF
For posixGroup objects (common in Linux systems), use memberUid
instead:
dn: cn=vipb,ou=groups,dc=example,dc=com
changetype: modify
add: memberUid
memberUid: fred
Confirm the change with:
ldapsearch -x -b "cn=vipb,ou=groups,dc=example,dc=com" "(objectClass=*)"
If you encounter errors:
- Insufficient access: Check your bind DN permissions
- No such object: Verify both user and group DNs
- Object class violation: Ensure the attribute matches the group type
To add several users at once:
dn: cn=vipb,ou=groups,dc=example,dc=com
changetype: modify
add: member
member: uid=fred,ou=people,dc=example,dc=com
member: uid=barney,ou=people,dc=example,dc=com
member: uid=wilma,ou=people,dc=example,dc=com
When working with LDAP directories, group membership is typically managed through the member
(or sometimes uniqueMember
for groupsOfUniqueNames) attribute. The process differs slightly between OpenLDAP and Active Directory implementations.
Before proceeding, ensure you have:
- LDAP administrator credentials
- The distinguished names (DNs) of both user and group
- Proper access rights to modify group objects
- Either
ldapmodify
command-line tool or ability to apply LDIF files
The most straightforward approach is using ldapmodify
with the following syntax:
ldapmodify -x -D "cn=admin,dc=example,dc=com" -W <For batch operations or scripting, create an LDIF file (e.g.,
add_user.ldif
):dn: cn=vipb,ou=groups,dc=example,dc=com changetype: modify add: member member: uid=fred,ou=people,dc=example,dc=comThen apply it with:
ldapmodify -x -D "cn=admin,dc=example,dc=com" -W -f add_user.ldifActive Directory Environments
For AD, use
memberOf
attribute on the user object instead:dn: uid=fred,ou=people,dc=example,dc=com changetype: modify add: memberOf memberOf: cn=vipb,ou=groups,dc=example,dc=comAdding Multiple Members
Multiple
member
attributes can be added in one operation:dn: cn=vipb,ou=groups,dc=example,dc=com changetype: modify add: member member: uid=fred,ou=people,dc=example,dc=com member: uid=barney,ou=people,dc=example,dc=comConfirm the addition with this search command:
ldapsearch -x -b "cn=vipb,ou=groups,dc=example,dc=com" "(objectClass=*)"
- Check objectClass: Ensure the group has
groupOfNames
or similar class- Validate DNs: Both user and group DNs must exist
- Schema compliance: Some schemas require at least one member
- Permissions: Verify your bind DN has write privileges
While less common, you can use
ldapadd
with a replace operation:dn: cn=vipb,ou=groups,dc=example,dc=com changetype: modify replace: member member: uid=existing_member,ou=people,dc=example,dc=com member: uid=fred,ou=people,dc=example,dc=comThis is useful when you need to completely replace the member list while adding new members.