Step-by-Step Guide to Installing OpenLDAP on Ubuntu 14.04
Installing OpenLDAP on Ubuntu 14.04 is crucial for administrators looking to implement centralized authentication and directory services. OpenLDAP is widely respected for its flexibility, open-source licensing, and integration capability with numerous applications and platforms. This article introduces OpenLDAP, explains its core functionality, and walks you through the detailed process of preparing an Ubuntu 14.04 environment for its successful installation.
The Lightweight Directory Access Protocol (LDAP) is an open, vendor-neutral protocol for accessing and maintaining distributed directory information services. It is most commonly used for storing information about users, groups, permissions, devices, and systems in a network.
OpenLDAP is an open-source implementation of the LDAP protocol developed by the OpenLDAP Project. It provides a robust framework for building scalable directory services in enterprise and cloud environments. Administrators rely on OpenLDAP for managing user credentials, performing centralized login management, and configuring shared directories.
Before diving into the installation, it’s important to understand why OpenLDAP is favored:
Ubuntu 14.04, also known as Trusty Tahr, is a Long-Term Support (LTS) release. Despite being outdated in modern settings, it still runs in many legacy systems that have yet to migrate. Understanding how to configure OpenLDAP on Ubuntu 14.04 remains relevant for system administrators tasked with maintaining existing infrastructure or gradually migrating from older systems.
A successful OpenLDAP deployment starts with thorough planning and proper preparation of the target environment. This section outlines the steps required to set up Ubuntu 14.04 in readiness for installing OpenLDAP.
For optimal performance, ensure the system meets the minimum hardware and software requirements:
Keeping the system updated ensures that all software packages are current and secure. Begin by updating the package list and upgrading installed packages.
bash
CopyEdit
sudo apt-get update
sudo apt-get upgrade
This will download and apply the latest available security patches and enhancements for Ubuntu 14.04.
Before proceeding with OpenLDAP, install essential utilities that will help during setup and troubleshooting:
bash
CopyEdit
sudo apt-get install vim net-tools wget curl unzip
These utilities provide text editing, network diagnostics, and download capabilities that will be used throughout the LDAP installation and configuration process.
Proper hostname configuration is essential for LDAP operations, especially when SSL/TLS certificates are used. Set a meaningful hostname for your server:
bash
CopyEdit
sudo hostnamectl set-hostname ldapserver
Verify the hostname:
bash
CopyEdit
hostname
Update the /etc/hosts file to associate the hostname with the server’s IP address:
bash
CopyEdit
sudo vim /etc/hosts
Add or modify the following line:
CopyEdit
127.0.1.1 ldapserver
This ensures the system identifies itself consistently by name.
LDAP servers must have a consistent IP address to avoid connectivity issues. Assign a static IP address using the /etc/network/interfaces configuration file.
bash
CopyEdit
sudo vim /etc/network/interfaces
Example configuration:
nginx
CopyEdit
auto eth0
iface eth0 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
Restart the networking service:
bash
CopyEdit
sudo service networking restart
Check the network interface to confirm the IP address:
bash
CopyEdit
ifconfig
LDAP operations often depend on proper DNS resolution. Make sure your server can resolve hostnames to IP addresses. Test DNS functionality with the ping or nslookup command:
bash
CopyEdit
ping google.com
If DNS isn’t resolving correctly, you may need to manually edit /etc/resolv.conf and add your DNS server:
nginx
CopyEdit
nameserver 8.8.8.8
This uses Google’s public DNS service.
Now that the system is prepared, install the core OpenLDAP packages:
bash
CopyEdit
sudo apt-get install slapd ldap-utils
The slapd package is the OpenLDAP server daemon, and ldap-utils includes command-line tools for managing directory entries.
After installation, you can reconfigure the slapd service using the built-in utility:
bash
CopyEdit
sudo dpkg-reconfigure slapd
This interactive configuration process asks for several key parameters:
These steps initialize the LDAP directory with a default base DN derived from your domain (e.g., dc=example,dc=org) and configure administrative access.
Ensure that the slapd service is running correctly:
bash
CopyEdit
sudo service slapd status
If it’s inactive or failed, restart the service:
bash
CopyEdit
sudo service slapd restart
Perform a test search using the ldapsearch command to ensure the server is responsive:
bash
CopyEdit
ldapsearch -x
This command performs an anonymous search. If successful, it will return a list of entries starting from the base DN.
OpenLDAP stores its configuration data in /etc/ldap/slapd.d/ using LDIF (LDAP Data Interchange Format). Unlike older versions, you should not edit these files directly. Instead, use LDAP commands like ldapmodify to make changes to the directory configuration.
The actual directory data is stored in /var/lib/ldap/. It contains the database files that hold your directory entries.
Enabling logging can help monitor activity and diagnose problems. OpenLDAP logs messages to the system log facility.
Edit the rsyslog configuration file:
bash
CopyEdit
sudo vim /etc/rsyslog.d/50-default.conf
Uncomment or add the following line:
lua
CopyEdit
local4.* /var/log/ldap.log
Restart rsyslog:
bash
CopyEdit
sudo service rsyslog restart
Now, OpenLDAP log messages will be recorded in /var/log/ldap.log.
Out of the box, the OpenLDAP server uses unencrypted communications. Before putting the server into production, consider enabling TLS encryption to secure communication between clients and the server.
Additionally, ensure that the administrative credentials (root DN) are stored securely and that access to configuration files is restricted to authorized users only.
In this first part of the OpenLDAP installation guide on Ubuntu 14.04, we covered the following:
With the server environment now correctly prepared and OpenLDAP installed, you’re ready to start customizing the directory structure, defining schemas, and populating data. These will be covered in the next part of the series.
After installing and verifying OpenLDAP on Ubuntu 14.04, the next essential step is configuring your directory structure. This phase focuses on designing your directory information tree (DIT), importing the necessary schemas, and populating your LDAP directory with base entries. These foundational tasks enable your LDAP server to organize and serve data efficiently.
The directory information tree is the hierarchical structure used to organize directory data. It resembles a filesystem, with a root and nested branches, each representing different organizational elements like users, departments, and groups.
For example, if your organization’s domain is example.org, the base distinguished name (DN) for your DIT will typically be dc=example,dc=org. Under this base, you might organize units such as:
This logical segmentation supports scalable directory management.
Before making modifications, it’s helpful to understand a few important LDAP components:
To build a working DIT, begin by creating an LDIF file that defines the base domain and organizational units. Use a text editor like Vim or nano.
bash
CopyEdit
vim base.ldif
Add the following content to define the base structure:
makefile
CopyEdit
dn: dc=example,dc=org
objectClass: top
objectClass: dcObject
objectClass: organization
o: Example Organization
dc: example
dn: ou=People,dc=example,dc=org
objectClass: organizationalUnit
You: People
dn: ou=Groups,dc=example,dc=org
objectClass: organizationalUnitYouu: Groups
This file creates the root domain and two organizational units. Adjust names and values to match your actual domain and organizational needs.
To apply the base LDIF to your directory:
bash
CopyEdit
ldapadd -x -D cn=admin,dc=example,dc=org -W -f base.ldif
After entering the admin password, OpenLDAP processes the LDIF and inserts the entries. If successful, the new structure becomes visible in the directory.
Check that the entries were added correctly:
bash
CopyEdit
ldapsearch -x-b dc=example,dc=org
This command performs a search starting from the base DN and returns all entries. The output should show the domain entry and the two organizational units.
OpenLDAP relies on schemas to define object classes and attribute types. The standard installation includes several pre-built schemas, such as:
These are typically located in /etc/ldap/schema/. To include these schemas in your configuration, you need to convert them to LDIF format if not already included.
Use the following commands to ensure essential schemas are loaded:
bash
CopyEdit
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/core.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/cosine.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/nis.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/inetorgperson.ldif
The inetOrgPerson schema is especially important for user accounts, as it includes commonly used attributes like cn, sn, uid, and mail.
Once the schemas are in place, you can begin adding user entries to your LDAP directory.
Create a new LDIF file for a sample user:
bash
CopyEdit
vim user.ldif
Add the following content:
yaml
CopyEdit
dn: uid=jdoe,ou=People,dc=example,dc=org
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
cn: John Doe
sn: Doe
uid: jdoe
uidNumber: 1000
gidNumber: 1000
homeDirectory: /home/jdoe
loginShell: /bin/bash
mail: jdoe@example.org
userPassword: {SSHA}5en6G6MezRroT3XKqkdPOmY/BfQ=
Note:
Example:
bash
CopyEdit
slappasswd
Enter your desired password, and the utility returns a hashed version, which you can paste into your LDIF file.
Use ldapadd again to import the new user:
bash
CopyEdit
ldapadd -x -D cn=admin,dc=example,dc=org -W -f user.ldif
Check the output to confirm successful addition. Then verify the entry:
bash
CopyEdit
ldapsearch -x -b uid=jdoe,ou=People,dc=example,dc=org
This returns all attributes of the new user.
Groups in LDAP allow you to manage collections of users more efficiently. Create a group LDIF file:
bash
CopyEdit
vim group.ldif
Example content:
yaml
CopyEdit
dn: cn=admins,ou=Groups,dc=example,dc=org
objectClass: posixGroup
cn: admins
gidNumber: 1000
memberUid: jdoe
Import the group:
bash
CopyEdit
ldapadd -x -D cn=admin,dc=example,dc=org -W -f group.ldif
Verify:
bash
CopyEdit
ldapsearch -x -b cn=admins,ou=Groups,dc=example,dc=org
This confirms the group exists and includes the user jdoe.
For better performance in large directories, configure indexing on frequently searched attributes. Edit or create an LDIF file:
bash
CopyEdit
vim indexing.ldif
Example:
makefile
CopyEdit
dn: olcDatabase={1}hdb,cn=config
change type: modify
add: olcDbIndex
olcDbIndex: uid eq
olcDbIndex: cn, sn eq, sub
Apply with:
bash
CopyEdit
ldapmodify -Y EXTERNAL -H ldapi:/// -f indexing. .ldif
Indexing helps OpenLDAP return search results faster, especially for large directories with thousands of users or groups.
Always back up after major changes. Use slapcat to create a full backup of the LDAP directory:
bash
CopyEdit
sudo slapcat -v -l backup.ldif
This creates a full export in LDIF format that can be restored with slapadd if needed.
In this part of the guide, you configured the core structure of your LDAP directory, added essential schemas, and created entries for users and groups. These foundational steps turn a basic OpenLDAP installation into a functional and scalable directory service:
With your OpenLDAP server successfully installed and the basic directory information tree (DIT) in place, the next critical step is securing the server. This part of the guide focuses on implementing access control policies (ACLs) and configuring TLS encryption. These tasks ensure that your directory remains secure and that only authorized users or services can access sensitive information.
Access control in OpenLDAP governs who can read or modify specific data in the directory. OpenLDAP’s ACL system is rule-based and is configured using the olcAccess attribute inside the dynamic configuration backend (cn=config). Each ACL is evaluated in order, and the first matching rule determines access.
A basic ACL follows this structure:
pgsql
CopyEdit
olcAccess: to <what> by <who> <access-level>
For example:
pgsql
CopyEdit
olcAccess: to attrs=userPassword by self write by anonymous auth by * none
This rule allows users to update their passwords, permits anonymous authentication, and denies access to everyone else.
Before modifying ACLs, ensure you have access to the configuration database (cn=config). You must authenticate using the UNIX root user or an authorized LDAP admin.
To list current ACLs:
bash
CopyEdit
ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b “olcDatabase={1}hdb,cn=config” olcAccess
This command shows all access rules currently in effect for your primary database.
Let’s create a file named acl.ldif to update the ACLs for your directory:
bash
CopyEdit
vim acl.ldif
Add the following content:
pgsql
CopyEdit
dn: olcDatabase={1}hdb,cn=config
change type: modify
replace: olcAccess
olcAccess: to attrs=userPassword by self write by anonymous auth by * none
olcAccess: to dn.base=”” by * read
olcAccess: to * by sel,f read by use, rs read by * none
Explanation:
Apply the ACLs with:
bash
CopyEdit
ldapmodify -Y EXTERNAL -H ldapi:/// -f acl.ldif
After modifying the ACLs, verify that they are being enforced. You can test access with specific accounts:
bash
CopyEdit
ldapsearch -x -D “uid=jdoe,ou=People,dc=example,dc=org” -W -b “dc=example,dc=org” uid
Then, try accessing restricted attributes, like userPassword, to ensure they are hidden or inaccessible depending on user privileges.
Transmission of LDAP data over the network without encryption is insecure. LDAP over TLS (LDAPS) or StartTLS prevents password and data sniffing.
You’ll first need a certificate authority (CA) and a server certificate. You can use self-signed certificates or obtain them from a trusted CA.
Use OpenSSL to create a certificate and private key:
bash
CopyEdit
sudo openssl req -new -x509 -nodes -out /etc/ssl/certs/ldap.crt -keyout /etc/ssl/private/ldap.key -days 365
Provide information when prompted (e.g., country, organization, domain). Make sure the certificate files are readable only by root:
bash
CopyEdit
sudo chmod 600 /etc/ssl/private/ldap.key
sudo chown openldap:openldap /etc/ssl/private/ldap.key
Create an LDIF file named tls.ldif:
bash
CopyEdit
vim tls.ldif
Insert the following:
vbnet
CopyEdit
dn: cn=config
change type: modify
add: olcTLSCertificateFile
olcTLSCertificateFile: /etc/ssl/certs/ldap.crt
add: olcTLSCertificateKeyFile
olcTLSCertificateKeyFile: /etc/ssl/private/ldap.key
Apply it:
bash
CopyEdit
ldapmodify -Y EXTERNAL -H ldapi:/// -f tls.ldif
This updates the global LDAP configuration to use your TLS certificate.
No, we configure the LDAP server daemon to allow secure connections. Open the slapd configuration file:
bash
CopyEdit
sudo dpkg-reconfigure slapd
During the prompts, choose:
Ensure the slapd service is listening on secure ports by checking:
bash
CopyEdit
sudo netstat -tnlp | grep slapd
You should see port 636 (LDAPS) and/or 389 (LDAP with optional StartTLS) in use.
Use openssl to confirm that the server accepts secure connections:
bash
CopyEdit
openssl s_client -connect localhost:636
A successful response with certificate details means your TLS setup is functional.
You can also test LDAP access over TLS:
bash
CopyEdit
ldapsearch -x -H ldaps://localhost -b dc=example,dc=org
If the connection works, your OpenLDAP server is now secured for encrypted communication.
If you plan to connect clients to the LDAP server, you’ll need to:
For example, on a client machine:
Copy the CA certificate:
bash
CopyEdit
Sudo cp ldap.crt /usr/local/share/ca-certificates/
sudo update-ca-certificates
Configure LDAP client settings:
Edit /etc/ldap/ldap.conf and add:
swift
CopyEdit
URI ldaps://ldap.example.org
BASE dc=example,dc=org
TLS_CACERT /etc/ssl/certs/ldap.crt
Test the connection:
bash
CopyEdit
ldapsearch -x -H ldaps://ldap.example.org -b dc=example,dc=org
To force all LDAP communication to occur over TLS and prevent insecure access, configure the firewall to block port 389 and only allow port 636.
Use UFW (Uncomplicated Firewall) to restrict access:
bash
CopyEdit
sudo ufw deny 389
sudo ufw allow 636
sudo ufw enable
This ensures all client-server LDAP communication remains encrypted.
In this section, you learned how to apply critical security configurations to your OpenLDAP server:
These steps protect user credentials and data from exposure, an essential requirement for production environments or any scenario involving sensitive information. The correct implementation of ACLs also ensures that only authorized users can interact with the directory.
With OpenLDAP installed, secured, and access control policies in place, the final part of this guide focuses on essential administrative tasks that maintain a smooth, scalable directory infrastructure. This includes managing users and groups, integrating a graphical administration interface, and ensuring your directory is backed up regularly for disaster recovery.
A functional directory service requires efficient user and group management. LDAP directories often store user account data to support centralized authentication for systems, applications, and services.
To create user entries in your directory, you need LDIF (LDAP Data Interchange Format) files that define the object classes and attributes of each user.
Here’s an example of an LDIF file named newuser.ldif:
ldif
CopyEdit
dn: uid=asmith,ou=People,dc=example,dc=org
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
cn: Alice Smith
sn: Smith
uid: asmith
uidNumber: 1001
gidNumber: 1001
homeDirectory: /home/asmith
loginShell: /bin/bash
mail: asmith@example.org
userPassword: {SSHA}hashedpasswordhere
To add the user:
bash
CopyEdit
ldapadd -x -D cn=admin,dc=example,dc=org -W -f newuser.ldif
Make sure the userPassword attribute contains an encrypted password. You can generate one using:
bash
CopyEdit
slappasswd
Use the output hash in the LDIF file.
Groups can be created using the posixGroup object class. Create a file named newgroup. ldif:
ldif
CopyEdit
dn: cn=developers,ou=Groups,dc=example,dc=org
objectClass: posixGroup
cn: developers
gidNumber: 1001
memberUid: asmith
Then add it using:
bash
CopyEdit
ldapadd -x -D cn=admin,dc=example,dc=org -W -f newgroup.ldif
You can add more members later using the ldapmodify command.
Using command-line utilities such as ldapsearch, ldapmodify, ldapadd, and ldapdelete, you can interact with the directory.
To list all users under a specific OU:
bash
CopyEdit
ldapsearch -x -b “ou=People,dc=example,dc=org” “(objectClass=posixAccount)”
To modify an attribute of an existing user, use an LDIF file like this:
ldif
CopyEdit
dn: uid=asmith,ou=People,dc=example,dc=org
change type: modify
replace: loginShell
loginShell: /bin/zsh
Then run:
bash
CopyEdit
ldapmodify -x -D cn=admin,dc=example,dc=org -W -f moduser.ldif
This structure provides a clean and controlled way to manage changes.
While command-line tools offer great control, a graphical interface simplifies administration for less experienced users.
Start by updating the package list and installing:
bash
CopyEdit
sudo apt-get update
sudo apt-get install phpldapadmin
Edit the configuration file at /etc/phpldapadmin/config.php to match your directory base and admin credentials. For example:
php
CopyEdit
$servers->setValue(‘server’,’base’,array(‘dc=example,dc=org’));
$servers->setValue(‘login’,’bind_id’,’cn=admin,dc=example,dc=org’);
Next, enable the Apache configuration and restart the web server:
bash
CopyEdit
sudo service apache2 restart
Access the web interface at http://localhost/phpldapadmin.
Make sure your web interface is accessible only from secure networks. Consider using HTTPS and configuring Apache to use SSL certificates.
Also, limit access to trusted IP addresses in the Apache configuration to avoid exposing your directory on public networks.
For large environments, scripting common tasks becomes essential. Bash and Python scripts using LDAP libraries allow automation of:
One useful tool for bulk operations is ldapvi, which opens LDAP entries in a text editor and allows batch editing.
Install it with:
bash
CopyEdit
sudo apt-get install ldapvi
Then run:
bash
CopyEdit
ldapvi -D cn=admin,dc=example,dc=org
Make changes in the interactive editor, save, and apply them directly.
Protecting your directory data is critical. OpenLDAP provides a few methods for backup and recovery.
The slapcat tool extracts the entire directory to an LDIF file. To create a full backup:
bash
CopyEdit
sudo slapcat -v -l backup_$(date +%F).ldif
This file can be stored in a secure location or uploaded to a backup server.
To back up only the configuration database:
bash
CopyEdit
sudo slapcat -n 0 -l config_backup.ldif
And to back up the main database:
bash
CopyEdit
sudo slapcat -n 1 -l data_backup.ldif
Use slapadd to restore a backup. First, stop the slapd service:
bash
CopyEdit
sudo service slapd stop
Then, clear the existing database:
bash
CopyEdit
sudo rm -rf /var/lib/ldap/*
Restore using:
bash
CopyEdit
sudo slapadd -l backup_file.ldif
Adjust ownership:
bash
CopyEdit
sudo chown -R openldap:openldap /var/lib/ldap
Finally, restart the service:
bash
CopyEdit
sudo service slapd start
Automate regular backups using cron. For example, add this line to the root’s crontab to back up daily:
bash
CopyEdit
0 2 * * * /usr/sbin/slapcat -l /var/backups/ldap_$(date +\%F).ldif
Rotate backups and implement off-site storage for critical environments.
LDAP logs are useful for monitoring activity, debugging errors, and auditing access. Configure syslog to capture relevant logs:
Edit /etc/rsyslog.conf and add:
bash
CopyEdit
local4.* /var/log/ldap.log
Then, in your slapd service, ensure the log level is set in /etc/default/slapd:
bash
CopyEdit
SLAPD_OPTIONS=”-d stats”
Restart rsyslog and slapd:
bash
CopyEdit
sudo service rsyslog restart
sudo service slapd restart
Now you can view logs:
bash
CopyEdit
tail -f /var/log/ldap.log
This final part of the guide has covered:
You now have a fully functional OpenLDAP deployment on Ubuntu 14.04, equipped with best practices for security, scalability, and manageability.
The steps outlined across the four parts of this series should serve as a solid foundation for anyone looking to deploy directory services in development, academic, or production environments.
Setting up OpenLDAP on Ubuntu 14.04 is a comprehensive process that, when done correctly, lays the groundwork for scalable, secure, and centralized identity management. Throughout this four-part guide, we’ve covered not only the core installation and configuration steps but also essential best practices for security, access control, user and group management, and backup strategies.
While Ubuntu 14.04 is an older release, understanding how to deploy OpenLDAP on it remains valuable for maintaining legacy systems and gaining foundational LDAP knowledge. The skills developed here are easily transferable to newer versions of Ubuntu and other Linux distributions.
A few key takeaways include:
With these practices in place, OpenLDAP can become a dependable and efficient backbone for centralized authentication and directory services in both small and large-scale environments.
If you’re managing LDAP in a production system, always test changes in a development environment first, keep security updated, and consider upgrading to supported OS versions when feasible.