This article explains how to setup your Linux host so you can login to it using a username and password from a LDAP server, making local users and passwords at the Linux host unnecessary.
If you want to administrate more than one Linux installation, you can either memorize a list of different user/password combinations per Linux host or use an identical user (with the same password) across all systems.
Both options are not much fun and a third option would be to install an LDAP server somewhere in the network and to authenticate all the Linux hosts against such LDAP server. That way users that are configured in the LDAP server can be allowed to login at any Linux host in the network.
There are a couple of configuration settings at a Linux host required to make this happen. These are the steps:
First of all a few packages must be installed that allow the system to become a LDAP client.
> sudo yum -y install openldap-clients openldap nss-pam-ldapd
Centos (or Red Hat) Linux offers two daemons that provide access to authentication providers (SSSD and NSLCD). In our case we decide to go with the legacy implementation, that is NSLCD. The authconfig tool will help us to configure what kind of data store to use for user credentials.
That being said, for old legacy ldap server support we have to use authconfig and pass the enableforcelegacy option. With that option we make sure SSSD is not being used implicitly, not even for a potentially supported configuration. The sssd daemon stopped and nslcd daemon started.
> sudo authconfig --enableforcelegacy --update
After issuing the above command you can check the status of the nslcd.service, as it should have been started already.
> systemctl status nslcd.service
● nslcd.service - Naming services LDAP client daemon.
Loaded: loaded (/usr/lib/systemd/system/nslcd.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2017-08-19 21:13:39 CEST; 3s ago
Process: 10498 ExecStart=/usr/sbin/nslcd (code=exited, status=0/SUCCESS)
Main PID: 10499 (nslcd)
CGroup: /system.slice/nslcd.service
└─10499 /usr/sbin/nslcd
Next we need the details of our LDAP server and structure within.
We need to know the name (or ip address) at which our LDAP server responds. In our example we do not use the LDAPS with TLS, but plain LDAP (at port 389). For the example let’s assume that the LDAP server responds at the your.domain.com URL.
In addition we need to know the base dn, which is the base point from which any LDAP query will be executed. In our example let’s assume the value dc=domain,dc=com.
With these two we can use the authconfig tool to make some configuration settings for us.
> sudo authconfig --enableldap --enableldapauth --ldapserver="your.domain.com" --ldapbasedn="dc=domain,dc=com" --update
The command above has altered configuration in two files: /etc/openldap/ldap.conf and /etc/nslcd.conf. While the configuration in /etc/openldap/ldap.conf will be sufficient for what we want to do, we have to add some more configuration to /etc/nslcd.conf in addition.
Please use your favorite editor, open up /etc/nslcd.conf and insert the following lines:
binddn uid=readeraccount,ou=people,dc=domain,dc=com
bindpw yourpasswordhere
# own filter for finding passwords
filter passwd (uid=*)
With the above changes we accomplish two things:
- we tell NSLCD to use a specific (non anonymous) user to perform all queries at the LDAP server and
- we narrow the search filter for finding a user’s password in the LDAP server.
NSLCD (our LDAP client) starts a session by connecting to the LDAP server. If not stated otherwise, this connection will be unauthenticated (anonymous bind). This is typically not allowed in most production environments, hence the client must provide a bind user and password. We configure an authenticated (Simple) BIND by specifying the user (binddn) and password (bindpw).
When an LDAP client requests information about a resource, it performs one or more resource queries depending on what it is looking up. Search queries sent to the LDAP server are created using the configured search base, filter, and the desired entry (uid=myuser) being searched for. If the LDAP directory is large, this search may take a significant amount of time. It is a good idea to define a more specific search base for the common maps such as passwd.
After these changes we have to restart the nslcd.service:
> sudo systemctl restart nslcd.service
Last but not least we should confirm our setup by attempting to get some user information from LDAP via our Linux console:
> getent passwd john
john:x:1000001:1000000:John Doe:/home/john:
Please note that the home directory is not the local home directory but the set home directory at the LDAP server. Although you could already successfully log in to the Linux host with the user “john”, there will be no home directory for john. Connecting the home directory is not covered in this article.