参考链接

https://blog.51cto.com/wzlinux/1836997

https://blog.51cto.com/11093860/2161809

1. 关闭ldap server机器上的防火墙

  1. systemctl stop firewalld.service #停止防火墙服务
  2. systemctl disable firewalld.service #禁用防火墙开机启动服务

在ldap client机器上telnet server机器的389端口

下图表示成功

Ldap centos 7搭建openldap client - 图1

2. 安装OpenLDAP客户端软件包

  1. yum install nss-pam-ldapd openldap-clients openldap -y

3. 配置/etc/openldap/ldap.conf

  1. vim /etc/openldap/ldap.conf

Ldap centos 7搭建openldap client - 图2

4. 配置/etc/pam_ldap.conf

  1. vim /etc/pam_ldap.conf

Ldap centos 7搭建openldap client - 图3

5. 配置/etc/nslcd.conf

  1. vim /etc/nslcd.conf

Ldap centos 7搭建openldap client - 图4

Ldap centos 7搭建openldap client - 图5

6. 修改system-auth 认证文件

  1. vim /etc/pam.d/system-auth
  2. ---------------------------------------------------------------
  3. auth sufficient pam_ldap.so use_first_pass
  4. account required pam_unix.so broken_shadow
  5. account [default=bad success=ok user_unknown=ignore] pam_ldap.so
  6. password sufficient pam_ldap.so use_authtok
  7. session optional pam_ldap.so
  8. session optional pam_mkhomedir.so skel=/etc/skel/ umask=0022

7. 修改nsswitch.conf 配置文件

  1. vim /etc/nsswitch.conf
  2. ---------------------------------------------------------------
  3. passwd: files ldap
  4. shadow: files ldap
  5. group: files ldap
  6. netgroup: files ldap
  7. automount: files ldap

8. 修改/etc/sysconfig/authconfig 认证文件

  1. vim /etc/sysconfig/authconfig
  2. ---------------------------------------------------------------
  3. USELDAP=yes
  4. USELDAPAUTH=yes
  5. USELOCAUTHORIZE=yes
  6. USESHADOW=yes

9. 修改sshd_config

  1. vim /etc/ssh/sshd_config
  2. ---------------------------------------------------------------
  3. UsePAM yes

10. 加载nslce进程

  1. systemctl restart nslcd
  2. systemctl restart sshd

11. 验证

  1. ldapsearch -H ldap://192.168.141.136 -x -b "uid=chenxin,ou=People,dc=demo,dc=com"

Ldap centos 7搭建openldap client - 图6

id chenxin

Ldap centos 7搭建openldap client - 图7