How to add user to OpenLDAP

Home > Search > How-to
  by

Before adding a group to OpenLDAP, ensure the People OU has been added.

 

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

 

Ensure the user was added to LDAP database.

~]# ldapsearch -x -b dc=example,dc=com
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

 



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 in the box below so that we can be sure you are a human.




Comments