Configuring LDAP on CentOS: Effortlessly Manage Hundreds of Servers Centrally

CentOS tutorial - IT technology blog
CentOS tutorial - IT technology blog

The Problem: When Local User Management Becomes a Nightmare

When I first started my career, the company only had about 5 CentOS 7 servers. Every time a new employee joined, I would tediously SSH into each machine to run useradd and set a password. Everything was fine until we scaled to 30, then 50 servers. At that point, revoking access when someone resigned became a total disaster. You simply can’t remember everywhere you created a user. Forgetting to delete an account on just one machine is a critical security vulnerability.

In reality, manual management takes about 10-15 minutes per new employee across 50 servers. With LDAP, that number drops to 10 seconds. Instead of storing users in a local /etc/passwd file, the server asks a central “operator”—the Directory Server: “Is this user allowed to log in?”

Quick Start: Configure LDAP Client in 5 Minutes

If you already have an LDAP Server (like OpenLDAP or Active Directory), use SSSD (System Security Services Daemon). This is a modern, stable, and much more secure method than older approaches. Here is a summary of the steps to get your CentOS machine connected immediately.

# 1. Install necessary packages
sudo yum install -y sssd sssd-ldap oddjob-mkhomedir openldap-clients

# 2. Configure authentication (CentOS 7 uses authconfig, CentOS 8/9 uses authselect)
# Example on CentOS 7:
sudo authconfig --enablesssd --enablesssdauth --enablemkhomedir --update

# 3. Set permissions and start services
sudo chmod 600 /etc/sssd/sssd.conf
sudo systemctl restart sssd
sudo systemctl enable sssd

Why Professionals Always Choose SSSD?

In the past, administrators often used nslcd or pam_ldap. However, from my hard-earned experience: Use SSSD at all costs. There are three main reasons why SSSD has become the standard:

  • Offline Caching: If the LDAP Server suddenly goes down, users can still log in thanks to cached data.
  • Reduced Load: It doesn’t constantly bother the LDAP Server for every ls -l command.
  • Multitasking: SSSD can seamlessly connect to both OpenLDAP and Windows Active Directory at the same time.

Step 1: Install Packages

We need sssd-ldap for communication and oddjob-mkhomedir to automatically create Home directories (like /home/username). Without this package, LDAP users won’t have a personal working environment when they log in.

sudo yum install sssd sssd-ldap oddjob-mkhomedir -y

Step 2: Set up the sssd.conf file

This is where the magic happens. This file usually doesn’t exist by default; you need to create it at /etc/sssd/sssd.conf. Make sure to update the ldap_uri and ldap_search_base parameters to match your infrastructure.

[sssd]
services = nss, pam
config_file_version = 2
domains = default

[domain/default]
id_provider = ldap
auth_provider = ldap
ldap_uri = ldap://ldap.itfromzero.com
ldap_search_base = dc=itfromzero,dc=com
ldap_id_use_start_tls = True
ldap_tls_cacertdir = /etc/openldap/cacerts
cache_credentials = True
ldap_tls_reqcert = allow
ldap_schema = rfc2307bis

There is a trap here: SSSD is extremely strict about security. It will refuse to start if the config file permissions are too loose. You must run the command: chmod 600 /etc/sssd/sssd.conf.

Step 3: Enable Automatic Home Directory Creation

Don’t let users get kicked out or end up in the root / directory upon login. The command below ensures the system automatically creates /home/user the first time they sign in.

# For CentOS 7:
sudo authconfig --enablemkhomedir --update

# For CentOS 8/9 (AlmaLinux, Rocky Linux):
sudo authselect select sssd with-mkhomedir --force
sudo systemctl enable --now oddjobd.service

Advanced: Traffic Security and Access Restrictions

Sending passwords over the standard port 389 means sending them in clear text. In production environments, I always require TLS (LDAPS – port 636) to encrypt data. This prevents sniffing attacks within the internal network.

If you want only the DevOps team to be able to SSH into production servers, add a filter to sssd.conf:

access_provider = ldap
ldap_access_filter = (memberOf=cn=sysadmins,ou=groups,dc=itfromzero,dc=com)

This configuration line is extremely powerful. It helps you categorize permissions: Developers can only access staging, while only SysAdmins have production access, even though they use the same LDAP account.

Real-world Troubleshooting Tips

During the operation of large systems, I’ve summarized 3 quick troubleshooting tips:

1. Check Basic Connectivity

Before blaming SSSD, use ldapsearch to see if the server can “see” the LDAP directory. If this command fails, check the Firewall or Network before editing the config file.

ldapsearch -x -H ldap://ldap.itfromzero.com -b "dc=itfromzero,dc=com"

2. Clear Cache When Info is “Lagging”

Sometimes you’ve just added a user to LDAP, but the id username command still says they aren’t found. This is because SSSD is using old cache. Clean it up with:

sudo sss_cache -E
sudo systemctl restart sssd

3. Read Logs to Diagnose

When SSSD acts up, don’t guess. Check the logs at /var/log/sssd/. You can increase debug_level = 5 in the config file to see detailed step-by-step handshakes between the Client and Server.

Conclusion

LDAP integration is not just a technical trick; it’s a professional management mindset. As systems grow, centralized management is the only way you can sleep soundly at night without worrying about leftover “ghost” accounts. Whether you are using CentOS 7 or newer versions like Rocky Linux, this authentication model remains the gold standard in the industry.

Share: