在CentOS 7上使用nslcd设置LDAP身份验证
我们将在CentOS 7服务器上配置LDAP身份验证。
软件
本文使用的软件:
- CentOS的7
- nss-pam-ldapd 0.8.13
- nscd 2.17
安装
nscd软件包是nss-pam-ldapd的依赖项,因此可以省略。
# yum install -y nss-pam-ldapd nscd
nss-pam-ldapd软件包允许LDAP目录服务器用作名称服务信息的主要来源。
该文件包含选项,每行一个选项,用于定义NSS查找和PAM操作映射到LDAP查找的方式。
文件“ nslcd.conf”包含选项,每行一个选项,用于定义NSS查找和PAM操作映射到LDAP查找的方式。
LDAP验证配置
SELinux设置为强制模式。
我们将使用一段时间前设置的OpenLDAP服务器。
在文本模式下运行authconfig。
请注意,该工具有一个GUI版本,请查找authconfig-gtk。
# authconfig-tui
我们的配置如下所示。
我们使用ldaps协议,因此直接绑定到636端口。
另一种选择是使用StartTLS(请参阅上面的“使用TLS”),但是,这要求我们在网络上打开一个普通的LDAP端口389(我们没有),因为客户端需要与该服务器建立未加密的连接。
首先是目录服务器,还要注意要连接到启用了TLS协议的LDAP服务器,我们需要一个CA证书,该证书签出了服务器的证书,该证书必须为PEM格式并复制到目录'/etc/openldap/cacerts /' 。
在使用自签名证书的情况下,应在文件“ /etc/nslcd.conf”中设置以下参数,以避免出现“对等证书颁发者已被使用标记为不信任”错误:
tls_reqcert never
一旦配置完成,假设LDAP服务器允许匿名读取访问,一切都应该很好。
在我们的情况下,它不是,因此我们还必须做一件事,并放置一些身份验证凭据才能成功绑定。
打开“ /etc/nslcd.conf”并添加以下行:
# The distinguished name to bind to the server with. # Optional: default is to bind anonymously. binddn cn=guest,dc=top # The credentials to bind with. # Optional: default is no credentials. # Note that if you set a bindpw you should check the permissions of this file. bindpw passwd
重新启动nslcd服务:
# systemctl restart nslcd
尝试使用LDAP用户登录:
# su - ldapuser1 Last login: Sat Mar 19 18:38:42 GMT 2015 on pts/1 su: warning: cannot change directory to /home/ldapuser1: No such file or directory id: cannot find name for group ID 2001 -bash-4.2$
我们可以忽略警告。
$id uid=2001(ldapuser1) gid=2001 groups=2001 context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
以下纯粹是供将来参考。
# grep -ve "^$" -ve "^#" /etc/openldap/ldap.conf TLS_CACERTDIR /etc/openldap/cacerts SASL_NOCANON on URI ldaps://ldap.theitroad.com BASE ou=Users,dc=theitroad.com,dc=top
# grep -ve "^$" -ve "^#" /etc/nslcd.conf uid nslcd gid ldap uri ldaps://ldap.theitroad.com base ou=Users,dc=theitroad.com,dc=top binddn cn=guest,dc=top bindpw passwd base group ou=Groups,dc=theitroad.com,dc=top tls_reqcert never ssl no tls_cacertdir /etc/openldap/cacerts
# grep ldap /etc/nsswitch.conf passwd: files sss ldap shadow: files sss ldap group: files sss ldap netgroup: files sss ldap automount: files ldap
故障排除
# journalctl -xlf
还要检查LDAP服务器日志。
给我自己的注释,在设置LDAP用户时,请确保他们定义了有效的loginShell属性,例如'/bin/bash'。
否则,我们可能会遇到以下问题:
This account is currently not available.
当loginShell属性设置为'/sbin/nologin'时,就会发生这种情况。