Centralized Authentication Configuration Manual with OpenLDAP
Author: Full-Stack Innovator Pro (Technical Review) Objective: Configure an OpenLDAP server to enable Single Sign-On (SSO) on Ubuntu clients...
Author: Full-Stack Innovator Pro (Technical Review) Objective: Configure an OpenLDAP server to allow Single Sign-On (SSO) on Ubuntu Desktop clients, including the automatic creation of home directories and SSL/TLS security.
📋 Lab Details
Sección titulada «📋 Datos de la Práctica»- Domain:
portelcore.local - Organization:
portelcore - Server (Static IP):
172.20.0.153 - Client: Ubuntu Desktop
- Base DN:
dc=portelcore,dc=local
PART 1: Server Configuration (Ubuntu Server)
Sección titulada «PARTE 1: Configuración del Servidor (Ubuntu Server)»1. Installation and Initial Configuration
Sección titulada «1. Instalación y Configuración Inicial»First, we will install the LDAP daemon (slapd) and management utilities.
sudo apt updatesudo apt install slapd ldap-utils -yNow we will reconfigure the package to create the database with our specific domain.
sudo dpkg-reconfigure slapdSetup wizard responses:
- Skip configuration?
No - DNS domain name?
portelcore.local - Organization name?
portelcore - Administrator password? (We define a secure password and remember it)
- Database engine?
MDB - Delete the database to purge?
No - Move the old database?
Sí
Once finished, we will check that the database has been created correctly by verifying the domain context:
slapcat | grep "dc=portelcore"2. Creation of the mapping file (LDIF)
Sección titulada «2. Creación del archivo de mapeo (LDIF)»This step is crucial for defining the directory architecture. We will create a .ldif file that defines the structure (Organizational Units), groups, and users.
We create the file:
nano usuaris_grups.ldifWe paste the following content into the file:
# Estructura Base: Unidades Organizativasdn: ou=people,dc=portelcore,dc=localobjectClass: organizationalUnitou: people
dn: ou=groups,dc=portelcore,dc=localobjectClass: organizationalUnitou: groups
# ---------------------------------------------------------# DEFINICIÓN DE GRUPOS# ---------------------------------------------------------
# Grupo 1: Administrador (GID 5000)dn: cn=Administrador,ou=groups,dc=portelcore,dc=localobjectClass: posixGroupcn: AdministradorgidNumber: 5000
# Grupo 2: Empleados (GID 5001)dn: cn=Empleats,ou=groups,dc=portelcore,dc=localobjectClass: posixGroupcn: EmpleatsgidNumber: 5001
# Grupo 3: Helpdesk (GID 5002)dn: cn=Helpdesk,ou=groups,dc=portelcore,dc=localobjectClass: posixGroupcn: HelpdeskgidNumber: 5002
# ---------------------------------------------------------# DEFINICIÓN DE USUARIOS# ---------------------------------------------------------
# Usuario 1: admin (Dentro de Administrador)dn: uid=admin,ou=people,dc=portelcore,dc=localobjectClass: inetOrgPersonobjectClass: posixAccountobjectClass: shadowAccountuid: adminsn: SystemgivenName: Administratorcn: Admin SystemdisplayName: Admin SystemuidNumber: 10000gidNumber: 5000userPassword: nolose123gecos: Admin SystemloginShell: /bin/bashhomeDirectory: /home/admin
# Usuario 2: user.portelcore (Dentro de Empleados)dn: uid=user.portelcore,ou=people,dc=portelcore,dc=localobjectClass: inetOrgPersonobjectClass: posixAccountobjectClass: shadowAccountuid: user.portelcoresn: UsergivenName: Portelcorecn: User PortelcoredisplayName: User PortelcoreuidNumber: 10001gidNumber: 5001userPassword: nolose123gecos: User PortelcoreloginShell: /bin/bashhomeDirectory: /home/user.portelcore
# Usuario 3: becario (Dentro de Helpdesk)dn: uid=becario,ou=people,dc=portelcore,dc=localobjectClass: inetOrgPersonobjectClass: posixAccountobjectClass: shadowAccountuid: becariosn: TechgivenName: Becariocn: Becario TechdisplayName: Becario TechuidNumber: 10002gidNumber: 5002userPassword: nolose123gecos: Becario TechloginShell: /bin/bashhomeDirectory: /home/becario3. Database Import
Sección titulada «3. Importación de la Base de Datos»We will inject the mapping file into the LDAP server.
ldapadd -x -D "cn=admin,dc=portelcore,dc=local" -W -f usuaris_grups.ldifIt will ask for the administrator password configured in step 1.
Verification:
If everything is correct, we will see messages from adding new entry. We verify that the user “becario” exists:
aldapsearch -x -b "dc=portelcore,dc=local" "(uid=becario)"PART 2: Client Configuration (Ubuntu Desktop)
Sección titulada «PARTE 2: Configuración del Cliente (Ubuntu Desktop)»Let's go to the client machine. This machine does not have users created locally; it will have to read them from the server.
1. LDAP client installation
Sección titulada «1. Instalación del cliente LDAP»We will install the necessary packages to connect the authentication system (PAM) and the name service (NSS) with LDAP.
sudo apt updatesudo apt install libnss-ldapd libpam-ldapd nscd -yGraphical wizard configuration:
- LDAP server URI:
ldap://172.20.0.153 - Search Base:
dc=portelcore,dc=local - Services: Make sure to check
passwd,group, andshadowusing the spacebar.
⚠️ IMPORTANT: Verify nsswitch.conf If users do not work after installation, we manually verify that the system searches in LDAP:
cat /etc/nsswitch.conf | grep passwdIf the word ldap does not appear at the end of the line, we edit the file sudo nano /etc/nsswitch.conf and add ldap to the end of lines passwd, group, and shadow.
2. Verify user visibility
Sección titulada «2. Verificar visibilidad de usuarios»The client must be able to "see" the users from the server.
getent passwd user.portelcoreExpected result: user.portelcore:x:10001:5001:User Portelcore:/home/user.portelcore:/bin/bash
3. Home Directory Automation
Sección titulada «3. Automatización del Directorio Home»We will configure PAM to automatically create the /home folder upon the first login.
Edit the common-session file:
sudo nano /etc/pam.d/common-sessionAdd this line at the end of the file:
session required pam_mkhomedir.so skel=/etc/skel umask=0077Restart the nscd service to clear the cache:
sudo systemctl restart nscdPART 3: Basic Testing
Sección titulada «PARTE 3: Pruebas Básicas»Test 1: Group Validation
Sección titulada «Prueba 1: Validación de Grupos»Log in with user admin (password: nolose123) via a Desktop terminal.
idResult: It must show uid=10000(admin) and gid=5000(Administrador).
Test 2: Graphical Login (SSO)
Sección titulada «Prueba 2: Inicio de Sesión Gráfico (SSO)»Log out and log in with becario / nolose123.
PART 4: Server and Client Security (SSL/TLS)
Sección titulada «PARTE 4: Seguridad del Servidor y Cliente (SSL/TLS)»To comply with security regulations, we will encrypt the connection.
4.1 Certificate Generation (On the Server)
Sección titulada «4.1 Generación de Certificados (En el Servidor)»We will install OpenSSL and create the certificates. Important: When asked for "Common Name (CN)", we will enter portelcore.local.
sudo apt install openssl -ysudo mkdir /etc/ldap/certs
# 1. Crear clave privada CAsudo openssl genrsa -out /etc/ldap/certs/ca.key 2048
# 2. Crear certificado CA (Autoridad)sudo openssl req -x509 -new -nodes -key /etc/ldap/certs/ca.key -sha256 -days 3650 -out /etc/ldap/certs/ca.crt -subj "/C=ES/ST=Barcelona/L=Granollers/O=Portelcore/CN=portelcore.local"
# 3. Crear clave privada del Servidorsudo openssl genrsa -out /etc/ldap/certs/ldap_server.key 2048
# 4. Crear petición de firma (CSR)sudo openssl req -new -key /etc/ldap/certs/ldap_server.key -out /etc/ldap/certs/ldap_server.csr -subj "/C=ES/ST=Barcelona/L=Granollers/O=Portelcore/CN=portelcore.local"
# 5. Firmar el certificado del servidor con nuestra CAsudo openssl x509 -req -in /etc/ldap/certs/ldap_server.csr -CA /etc/ldap/certs/ca.crt -CAkey /etc/ldap/certs/ca.key -CAcreateserial -out /etc/ldap/certs/ldap_server.crt -days 365 -sha256We will assign permissions so that LDAP can read the keys:
sudo chown -R openldap:openldap /etc/ldap/certs/sudo chmod 600 /etc/ldap/certs/*.key4.2 OpenLDAP Configuration to use TLS (Server)
Sección titulada «4.2 Configuración de OpenLDAP para usar TLS (Servidor)»We will create a tls_config.ldif file to indicate where the certificates are located:
nano tls_config.ldifContent:
dn: cn=configchangetype: modifyreplace: olcTLSCACertificateFileolcTLSCACertificateFile: /etc/ldap/certs/ca.crt-replace: olcTLSCertificateFileolcTLSCertificateFile: /etc/ldap/certs/ldap_server.crt-replace: olcTLSCertificateKeyFileolcTLSCertificateKeyFile: /etc/ldap/certs/ldap_server.keyWe will apply the configuration:
sudo ldapmodify -Y EXTERNAL -H ldapi:/// -f tls_config.ldifWe will edit /etc/default/slapd to ensure it accepts secure connections:
sudo nano /etc/default/slapdWe will look for SLAPD_SERVICES and leave it like this:
SLAPD_SERVICES="ldap:/// ldapi:/// ldaps:///"
We will restart:
sudo systemctl restart slapd4.3 Client Configuration for SSL (Ubuntu Desktop)
Sección titulada «4.3 Configuración del Cliente para SSL (Ubuntu Desktop)»⚠️ CRITICAL PREVIOUS STEP: DNS Configuration
Since the certificate is issued to portelcore.local, we cannot use the IP directly in the SSL configuration.
-
We will edit the client's hosts file:
Ventana de terminal sudo nano /etc/hosts -
We will add this line at the end:
172.20.0.153 portelcore.local
SSL configuration steps:
-
Transfer the CA: We need to download the authority certificate from the server to the client.
We will open a terminal on the Client and execute: (We will replace
usuari_remotwith our server user, for example,alex)Ventana de terminal # 1. Descargar archivoscp user.portelcore@172.20.0.153:/etc/ldap/certs/ca.crt .# 2. Mover al lugar correctosudo mv ca.crt /etc/ssl/certs/# 3. Asignar permisos de lectura para todossudo chmod 644 /etc/ssl/certs/ca.crt -
Configure the LDAP daemon: We will edit the configuration file:
Ventana de terminal sudo nano /etc/nslcd.confWe will make TWO important changes:
Change A: We will modify the URI to use the domain name, not the IP:
uri ldap://portelcore.localChange B: We will enable TLS and the certificate:
ssl start_tlstls_reqcert demandtls_cacertfile /etc/ssl/certs/ca.crt -
Restart client services:
Ventana de terminal sudo systemctl restart nslcd -
Verify Connection:
getent passwd admin
PART 5: Professional Audit (tcpdump + Wireshark)
Sección titulada «PARTE 5: Auditoría Profesional (tcpdump + Wireshark)»In production environments (Servers without GUI), the best practice is to capture the traffic on the server and analyze it later on a desktop machine.
5.1 Traffic Capture (On the Server)
Sección titulada «5.1 Captura de Tráfico (En el Servidor)»-
We will install the capture tool:
Ventana de terminal sudo apt install tcpdump -y -
We will start the capture by filtering the LDAP port (389) and saving it to a file
.pcap:Ventana de terminal sudo tcpdump -i any port 389 -w /tmp/ldap_capture.pcap(We will leave the terminal open while we perform the next step).
5.2 Traffic Generation (On the Client)
Sección titulada «5.2 Generación de Tráfico (En el Cliente)»-
We will open a terminal on the Client (Ubuntu Desktop).
-
We will perform a query to generate traffic:
getent passwd user.portelcore -
We will return to the Server and stop the capture with
Ctrl + C.
5.3 File Analysis (On the Client)
Sección titulada «5.3 Análisis del Archivo (En el Cliente)»Now we will transfer the capture file to the Client to analyze it with Wireshark (which has a graphical interface).
-
On the Client, we will download the file:
scp usuari@172.20.0.153:/tmp/ldap_capture.pcap . -
We will install and open Wireshark:
Ventana de terminal sudo apt install wireshark -ywireshark ldap_capture.pcap
What should we look for?
- We will look for packets with protocol
LDAP. - We will look for the “startTLSRequest” packet.
- Right after, TLSv1.2 or TLSv1.3 packets should appear.
- Success test: We will attempt to read the content of an “Application Data” packet. If we only see unreadable (encrypted) characters, the security is working correctly.
APPENDIX 1: Solution if the Server IP changes
Sección titulada «ANEXO 1: Solución si cambia la IP del Servidor»If we already have the client configured and the server IP changes (for example, from 192.168.1.100 to 172.20.0.153), reinstallation is not necessary.
Option A (Recommended - Assistant):
We will run the reconfiguration of the nslcd package:
sudo dpkg-reconfigure nslcdWe will enter the new IP when requested for the URI (ldap://172.20.0.153).
Option B (Manual):
-
We will edit the nslcd daemon configuration file:
Ventana de terminal sudo nano /etc/nslcd.conf -
We will modify the URI line: We will look for the line that begins with
uriand change the old IP for the new one. Before:uri ldap://192.168.1.100Now:uri ldap://172.20.0.153(We will save with Ctrl+O and exit with Ctrl+X)
-
We will restart the services to apply changes:
Ventana de terminal sudo systemctl restart nslcdsudo systemctl restart nscd -
We will verify the connection:
getent passwd user.portelcore
APPENDIX 2: Troubleshooting
Sección titulada «ANEXO 2: Resolución de Problemas (Troubleshooting)»If getent passwd returns nothing, but we have a network connection, the problem is usually SSL.
Step 1: Real-time diagnosis We will stop the daemon and run it manually in debug mode to see why it rejects the connection.
sudo systemctl stop nslcdsudo nslcd -dWe will read the last lines. If we see “hostname does not match CN”, it means we have the IP in the configuration file instead of the name.
Step 2: URI Verification
We will ensure that in /etc/nslcd.conf we have exactly the following:
uri ldap://portelcore.local
(If we have ldap://172.20.0.153, the certificate will fail).

