Member-only story

Create new user in LDAP using ldif

Donald Le
1 min readMar 2, 2021

--

Example ldif file

dn: ou=People,dc=example,dc=com
objectClass: organizationalUnit
ou: People

dn: ou=Groups,dc=example,dc=com
objectClass: organizationalUnit
ou: Groups

dn: cn=Artist,ou=Groups,dc=example,dc=com
objectClass: posixGroup
cn: SUBGROUP
gidNumber: 5000

dn: uid=ben,ou=People,dc=example,dc=com
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
uid: ben
sn: Affleck
givenName: Ben
cn: Ben Affleck
displayName: Ben
uidNumber: 10001
gidNumber: 5000
userPassword: benspassword
gecos: Ben Affleck
loginShell: /bin/bash
homeDirectory: USERDIRECTORY1

dn: uid=bob,ou=People,dc=example,dc=com
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
uid: bob
sn: Marley
givenName: Bob
cn: Bob Marley
displayName: Bob
uidNumber: 10002
gidNumber: 5000
userPassword: bobspassword
gecos: Bob Marley
loginShell: /bin/bash
homeDirectory: USERDIRECTORY2

Create a new file base.ldif with the above information.

We need to use admin credentials in order to create new users

ldapadd -x -W -D "cn=admin,dc=example,dc=com" -f base.ldif

Then we have it, new entries are added

adding new entry "ou=People,dc=example,dc=com"adding new entry "ou=Groups,dc=example,dc=com"adding new entry "cn=Artist,ou=Groups,dc=example,dc=com"adding new entry "uid=ben,ou=People,dc=example,dc=com"adding new entry "uid=bob,ou=People,dc=example,dc=com"

After this, we can login to the existing running system with the new users.

Happy coding ~~

--

--

Donald Le
Donald Le

Written by Donald Le

A passionate automation engineer who strongly believes in “A man can do anything he wants if he puts in the work”.

No responses yet