朋友们看了标题可能就会嘀咕,LDAP这么简单老旧的东西,怎么可以作为新时代下异构平台整合的一个策略呢,业界有许多主流的开源软件都可以提供和SSSD相媲美的功能不去用? 在这我先申明一下,LDAP 功能上的确有不少限制, 不过它作为很早就出现的技术被各个版本的操作系统所兼容,比如redhat4, solaris 早期版本等. SSSD/Samba 对于老旧系统的支持还是存疑的. 所以对于特定场景来说,LDAP不失为一个最适合的选择。而且LDAP部署简单,实施更加高效.
我在实验过程中最看中LDAP 1 简单。 2 支持posix attributes, 而且配置也简单,不像Samba/Winbind 看着行其实有不少问题. 很多的开源软件,比如PBIS (Powerbroker Identity Service Open)在免费版本里是不支持posix attributes的。这凸显了LDAP的核心价值,简单有用。很多时候linux机器使用AD账户登录主要是为了统一认证,没有复杂的管理场景. LDAP往往满足需求;
(以Redhat/centos 为例,Ubuntu可以自行切换命令.)
1. 安装所需LDAP模块
yum install libpam-ldapd libnss-ldapd
2. 配置ldap Pam 模块:
一般情况下,安装ldap 模块会自动帮你在/etc/pam.d/的配置文件中做好必要的配置。如果没有的话,请依次查看 common-account, common-auth, common-password, common-session, 确保pam_ldap.so 是在的.
具体可参考:
account [default=bad success=ok user_unknown=ignore] pam_ldap.so
auth sufficient pam_ldap.so use_first_pass
password sufficient pam_ldap.so
session optional pam_ldap.so
3. 配置NSS-ldap:
编辑/etc/ldap.conf
# Your LDAP server. Must be resolvable without using LDAP.
uri ldap://10.0.0.1
# The distinguished name of the search base.
base dc=,dc=
binddn cn=proxyuser,cn=users,dc=domain,dc=com
bindpw yourpassword
开启RFC2307AD mappings:
# RFC 2307 (AD) mappings nss_map_objectclass posixAccount user nss_map_objectclass shadowAccount user nss_map_attribute uid sAMAccountName nss_map_attribute homeDirectory unixHomeDirectory nss_map_attribute shadowLastChange pwdLastSet nss_map_objectclass posixGroup group nss_map_attribute uniqueMember member pam_login_attribute sAMAccountName pam_filter objectclass=User pam_password ad
然后配置/etc/nsswitch.conf:
passwd: files ldap
group: files ldap
shadow: files ldap
hosts: files dns ldap
networks: files ldap
protocols: db files
services: db files
ethers: db files
rpc: db files
netgroup: nis
4. 配置和AD的沟通:
-> 确保名称解析/IP是正确的. linux可以正常找到域控;
-> 如果有需要,配置ldap的proxy agent account用来和AD做绑定;
5. 检验LDAP的作用:
getent password
看是否可以看到域的用户;能看到就正常了;
su - domainuser
能正常使用域账户身份登录,就正常了: 自动家目录的创建可以参考这篇文章:
https://wiki.debian.org/LDAP/PAM
https://unix.stackexchange.com/questions/131195/home-directories-and-pam-d-using-ldap