FreeKB - OpenLDAP Add user
OpenLDAP - Add user

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/ /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
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.

Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter eade6 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |