OpenLDAP - Add user
by
Jeremy Canfield |
Updated: March 11 2020
| OpenLDAP articles
Before adding a person to OpenLDAP, ensure the People OU has been created.
Create a new user.
~]# useradd JohnDoe
Give the user a password.
~]# passwd JohnDoe
Redirect the newly add user to a new file.
~]# cat /etc/passwd | grep JohnDoe > /tmp/user
File /tmp/user should have the following.
JohnDoe:x:1001:1001:John Doe:/home/JohnDoe:/bin/bash
Migrate the contents of the /etc/user file into the user.ldif file.
~]# /usr/share/migrationtools/migrate_passwd.pl /tmp/user /etc/openldap/slapd.d/user.ldif
The LDIF file should now contain details for the user.
~]# /etc/openldap/slapd.d/user.ldif
dn: uid=JohnDoe,ou=People,dc=example,dc=com
uid: JohnDoe
cn: JohnDoe
sn: JohnDoe
mail: JohnDoe@example.com
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword: {crypx}asldfjalkfjaslkfavkjalkalkvjalkvjalfjadofiasoifjelemlaemlakemla
shadowLastChange: 17483
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 1001
gidNumber: 1001
homeDirectory: /home/JohnDoe
gecos: JohnDoe
Import the user into LDAP database.
~]# ldapadd -x -W -D "cn=Manager,dc=example,dc=com" -f /etc/openldap/slapd.d/user.ldif
Enter LDAP password: ******
adding new entry "cn=JohnDoe,ou=People,dc=example,dc=com"
The ldapsearch command can be used to ensure the user was added to LDAP database.
Did you find this article helpful?
If so, consider buying me a coffee over at