How To Install OpenLDAP on Debian 11

Install OpenLDAP on Debian 11

In this tutorial, we will show you how to install OpenLDAP on Debian 11. For those of you who didn’t know, OpenLDAP is a free and open-source implementation of the Lightweight Directory Access Protocol released under the OpenLDAP Public License. It’s a platform-independent protocol that can be used for centralized authentication and directory access services such as email and other applications.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the OpenLDAP on a Debian 11 (Bullseye).

Prerequisites

  • A server running one of the following operating systems: Debian 11 (Bullseye).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo useror access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install OpenLDAP on Debian 11 Bullseye

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update
sudo apt upgrade

Step 2. Installing OpenLDAP on Debian 11.

By default, OpenLDAP is available on Debian 11 base repository. So, now run the following command below to install the OpenLDAP packages to your Debian system:

sudo apt install slapd ldap-utils

During the installation, you will be asked to set up the password for the OpenLDAP admin user:

Install OpenLDAP on Debian 11

Step 3. Configuring OpenLDAP Server.

Now we set up the FQDN (Fully Qualified Domain Name) of the server using the following command:

sudo hostnamectl set-hostname ldap.idroot.us

Next, edit the ‘/etc/hosts‘ file using a favorite text editor:

sudo nano /etc/hosts

Copy and paste the following configuration:

192.168.77.21 ldap.idroot.us ldap

Save and close the file, then log out from your current SSH session and log in again to your server. Once logged in, run the command below to reconfigure the OpenLDAP package ‘slapd‘:

sudo dpkg-reconfigure slapd

You will then need to answer the following questions:

Install OpenLDAP on Debian 11 Bullseye

To verify the OpenLDAP configuration, run the ‘slapcat‘ command:

sudo slapcat

Finally, restart the ‘slapd‘ service to apply new changes:

sudo systemctl restart slapd
sudo systemctl status slapd

Step 4. Configuring Firewall.

By default, the UFW firewall is enabled on Debian. Depending on your OpenLDAP configuration file, open ports LDAP and LDAPS to allow traffic:

sudo ufw allow LDAP
sudo ufw allow LDAPS
sudo ufw reload

Step 5. Setting Up User Group.

Now we set up the group on the OpenLDAP server using the LDIF (LDAP Data Interchange Format) file:

sudo nano /etc/ldap/users.ldif

Add the following configuration:

dn: ou=chedelics,dc=idroot,dc=us
objectClass: organizationalUnit
ou: chedelics

*This configuration will create a new group named ‘chedelics’ on the domain name ‘idroot.us. 

Save and close the file, then run the ‘ldapadd‘ command below to add the group defined on the ‘users.ldif file:

sudo ldapadd -D "cn=admin,dc=idroot,dc=us" -W -H ldapi:/// -f /etc/ldap/users.ldif

To verify the group ‘chedelics’, run the ‘ldapsearch‘ command below. This command will show available groups on the OpenLDAP server:

sudo ldapsearch -x -b "dc=idroot,dc=us" ou

Step 6. Setting Up New User.

Once set up the group on the OpenLDAP, you can now add a new user to the OpenLDAP server:

sudo nano meilana.ldif

Add the following configuration:

# Add user alice to LDAP Server
dn: cn=alice,ou=chedelics,dc=idroot,dc=us
objectClass: top
objectClass: account
objectClass: posixAccount
objectClass: shadowAccount
cn: alice
uid: alice
uidNumber: 10001
gidNumber: 10001
homeDirectory: /home/meilana
userPassword: Your-Strong-Password
loginShell: /bin/bash

Save and close the file, then run the ‘ldapadd‘ command below to add a new user based on the ‘meilana.ldif‘ file:

sudo ldapadd -D "cn=admin,dc=idroot,dc=us" -W -H ldapi:/// -f meilana.ldif

Finally, run the ‘ldapsearch‘ command below to get the list of users on the OpenLDAP server:

sudo ldapsearch -x -b "ou=chedelics,dc=idroot,dc=us"

Congratulations! You have successfully installed OpenLDAP. Thanks for using this tutorial for installing the latest version of the OpenLDAP on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official OpenLDAP website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!