Skip to content

Step by step guide to Install and configure OpenLDAP server on ubuntu 18.04

Step by step guide to Install and configure OpenLDAP server on ubuntu 18.04

OpenLDAP server is an open-source implementation of the Lightweight Directory Access Protocol (LDAP). It serves as a centralized directory service, storing and managing user, group, and network information. It facilitates authentication, authorization, and user access to various applications and resources across a network.

In this post we will learn step by step guide to Install and configure OpenLDAP server on ubuntu 18.04

Step by step guide to Install and configure OpenLDAP server on ubuntu 18.04

Set hostname.

#hostnamectl set-hostname openldapubuntu

Check OS Version

Update ubuntu

Install OpenLDAP

#apt -y install slapd ldap-utils

Enter Administrator password. Here we are using password “redhat” for our setup

This will complete the installation. We can use command “slapcat” command to verify.

Step by step guide to Install and configure OpenLDAP server on ubuntu 18.04

Configure OpenLDAP

use below command to start OpenLDAP configuration.

#dpkg-reconfigure slapd

Step by step guide to Install and configure OpenLDAP server on ubuntu 18.04

Select “NO

  • Enter domain name.
  • Enter organization name

Enter ldap admin password. Here I have use password “redhat123”

  • Choose database type. I am using “mdb” as my database type.
  • Select No when asked to remove database.
  • Now select “Yes” to move the old OpenLDAP database, and the configuration is completed.

Check LDAP server status.

#systemctl status slapd

  • user “slapcat” command to check LDAP configuration.

#slapcat

  • Serach ldap database

#ldapsearch -x -b dc=alien,dc=world,dc=com

Create an Organizational Unit

Now let’s create an OU (organizational unit) and add users under it. Here my OU name is “fly

vim basedn.ldif

dn: ou=fly,dc=alien,dc=world,dc=com
objectClass: organizationalUnit
ou: fly

save and exit

Now add the file by running the below command

#ldapadd -x -D cn=admin,dc=alien,dc=world,dc=com -W -f basedn.ldif

  • Now check if the new OU has added or not with slapcat command.

Add Users

Now let’s add two users under “fly” OU. For that we need to create users.ldif file for users

#vim users.ldif

dn: cn=user1,ou=fly,dc=alien,dc=world,dc=com
uid=u01
displayName: user1
userPassword: 12345
objectClass: inetOrgPerson
givenName: user1
sn: u1
cn=user1

dn: cn=user2,ou=fly,dc=alien,dc=world,dc=com
uid=u02
displayName: user2
userPassword: 12345
objectClass: inetOrgPerson
givenName: user2
sn: u2
cn=user2

  • user below ldapadd command to add users.

#ldapadd -x -D cn=admin,dc=alien,dc=world,dc=com -W -f users.ldif

Now, with slapcat command we can check and found that used is added

Delete a OpenLDAP user.

To delete a user, we have created a file “deleteuser.ldif” and paste below content. Save and exit

vim deleteuser.ldif

dn: cn=user2,ou=fly,dc=alien,dc=world,dc=com
changetype: delete

Now run the below command

ldapmodify -c -x -W -D “cn=admin,dc=alien,dc=world,dc=com” -f userdelete.ldif

Now check ldap database with slapcat or below command, we will find that user2 is deleted.

#ldapsearch -x -b dc=alien,dc=world,dc=com

Change user password

With the help of below command we have change the password of user “user1“. It will prompt for new password and admin password.

#ldappasswd -H ldap:/// -x -D “cn=admin,dc=alien,dc=world,dc=com” -W -S “cn=user1,ou=fly,dc=alien,dc=world,dc=com”

  • Enter new password
  • Enter ldap admin password

Change the RootDN password.

Run slappasswd to get the hash for new password. My new password is 123redhat

root@openldapubuntu:~# slappasswd
New password:
Re-enter new password:
{SSHA}vARkPO1LrwnbSdiKY0Tutz+Z9GtcUOVX

Now create a file named “changerootpassword.ldif” with below content

dn: olcDatabase={1}mdb,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: {SSHA}vARkPO1LrwnbSdiKY0Tutz+Z9GtcUOVX command:

Now run bleow ldapmodify command

#ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f changerootpassword.ldif

also run below command to update the database. Enter the same password while creating the new hash and enter old root password in “Enter LDAP Password. This will update the rootDN password

#ldappasswd -x -D cn=admin,dc=alien,dc=world,dc=com -W -S
New password:
Re-enter new password:
Enter LDAP Password:

Conclusion

In this post I tried to explain as simple as possible, how to install and configure OpenLDAP server on Ubuntu OS. Thanks for reading.

For more information: Visit the Ubuntu Documentation.

Also Read my other Posts: