How To Install OpenLDAP on Ubuntu 22.04 LTS
In this tutorial, we will show you how to install OpenLDAP on Ubuntu 22.04 LTS. For those of you who didn’t know, OpenLDAP is an open-source implementation of the Lightweight Directory Access Protocol (LDAP), which is used for managing user accounts and other directory information on a network. It provides a centralized authentication system for networked computers, making it easier to manage user accounts and access rights.
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 Ubuntu 22.04 (Jammy Jellyfish). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.
Prerequisites
- A server running one of the following operating systems: Ubuntu 22.04, 20.04, and any other Debian-based distribution like Linux Mint.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for OpenLDAP.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install OpenLDAP on Ubuntu 22.04 LTS Jammy Jellyfish
Step 1. First, make sure that all your system packages are up-to-date by running the following apt
commands in the terminal.
sudo apt update sudo apt upgrade
Step 2. Installing OpenLDAP on Ubuntu 22.04.
By default, OpenLDAP is available on Ubuntu 22.04 base repository. Now run the following command below to install the latest version of OpenLDAP to your Ubuntu system:
sudo apt install slapd ldap-utils
During the installation process, you will be prompted to provide a password for the administrator account. This password is used to manage the OpenLDAP server.
Step 3. Configure OpenLDAP.
After the installation is complete, we need to configure the OpenLDAP server. This will launch a configuration wizard. Follow the steps below to configure OpenLDAP:
sudo dpkg-reconfigure slapd
Step 4. Add Users to OpenLDAP Server.
Now that we have our OpenLDAP server running and configured, we can begin adding users to it. The following commands will create a new organizational unit (OU) for our users and add a new user to the directory.
nano /etc/ldap/ldif/newusers.ldif
Add the following file:
dn: ou=users,dc=my-domain,dc=com objectClass: organizationalUnit ou: users
Save and close the file, then use the ldapadd
command to add the OU to the directory:
sudo ldapadd -x -D cn=admin,dc=my-domain,dc=com -W -f /etc/ldap/ldif/newusers.ldif
You will be prompted to enter the LDAP administrator password. Enter the password and press Enter.
Next, let’s add a new user to the directory. Create a new LDIF file:
sudo nano /etc/ldap/ldif/newuser.ldif
Add the following file:
dn: cn=meilana,ou=users,dc=my-domain,dc=com objectClass: top objectClass: person objectClass: organizationalPerson objectClass: inetOrgPerson cn: meilana sn: mei givenName: geulis mail: meilana@my-domain.com userPassword: {SSHA}password_hash
Replace “meilana
” with the username, you want to use and “password_hash
“With the SHA-1 hash of the user’s password. You can generate a new password hash using the slappasswd
command:
sudo slappasswd
Enter the password you want to use for the user and press Enter. The command will output a password hash. Copy the hash and replace “password_hash
” in the LDIF file with the hash.
Save and close the file. Then, use the ldapadd
command to add the user to the directory:
sudo ldapadd -x -D cn=admin,dc=my-domain,dc=com -W -f /etc/ldap/ldif/newuser.ldif
You will be prompted to enter the LDAP administrator password. Enter the password and press Enter.
Step 4. Firewall Configuration.
By default, the OpenLDAP server listens on port 389 for LDAP traffic. We need to configure the firewall to allow traffic on this port. Run the following command to open the port:
sudo ufw allow ldap
Step 5. Test OpenLDAP.
To test our OpenLDAP server, we can use the ldapsearch
command to retrieve information from the directory. To retrieve a list of all entries in the directory, run the following command:
sudo ldapsearch -x -b dc=my-domain,dc=com
To search for a specific entry, run the following command:
sudo ldapsearch -x -b dc=my-domain,dc=com "(cn=meilana)"
This will search for the user “meilana
” in the directory. If the search is successful, you should see the user’s information displayed in the terminal.
Congratulations! You have successfully installed OpenLDAP. Thanks for using this tutorial for installing the OpenLDAP on Ubuntu 22.04 LTS Jammy Jellyfish system. For additional help or useful information, we recommend you check the official OpenLDAP website.