关于 nscd,nslcd 和 sssd 套件的综述

本文详细对比了nslcd与nscd的服务功能与配置要点,阐述了它们在处理LDAP查询及缓存上的差异,并讨论了在RedHat与Debian系统中的配置实践。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


关于 nscd,nslcd 和 sssd 套件的综述

旧式libnss_ldap和pam_ldap的库文件:
/lib/x86_64-linux-gnu/libnss_ldap-2.13.so
/lib/x86_64-linux-gnu/security/pam_ldap.so

新式libnss_ldapd和libpam_ldapd(即nslcd)的库文件:
/lib/x86_64-linux-gnu/libnss_ldap.so.2
/lib/x86_64-linux-gnu/security/pam_ldap.so

套件sssd自带的libnss_sss和pam_sss库文件:
/lib/libnss_sss.so.2
/lib/security/pam_sss.so


********************************************************************************
注意:不要混淆了 nscd 和 nslcd(local LDAP name service daemon)两个完全不同的服务
********************************************************************************
nslcd(即nss-pam-ldapd)本身包括了一个瘦身版本的 PAM 模块和一个瘦身版本的 NSS 模块,
但您依然可以单独构建这三个部分(NSS 模块,PAM 模块和 nslcd server),这意味着您
依然还可以使用 pam_ldap 套件和使用来自 nss-pam-slapd 套件的NSS模块,但目前此套件
不能与nss_ldap套件在同一个系统中同时并行使用。

nslcd 套件的正式名称是 Daemon for NSS and PAM lookups using LDAP(nss-pam-ldapd),
它最初由PADL软件公司的Luke Howard开发,作为 nss_ldap 的分支,名为 nss-ldapd 套件。
2006年,West Consulting 的  Arthur de Jong 将这个库分成 NSS 部分和 server 部分并
重写了大部分代码。当 OpenLDAP 的 nssov 模块的 Howard Chu 贡献出 PAM 代码时,这个
软件被重新命名为 nss-pam-ldapd 套件。但在 RedHat 和 Debian 中此套件有不同的名称:

CentOS:  nss-pam-ldapd  - An nsswitch module which uses directory servers
Ubuntu:  nslcd  - Daemon for NSS and PAM lookups using LDAP

nslcd自带pam模块,因此完全不需要配置/etc/pam.d/目录下的服务,它不用ldap.conf配置
文件,而使用自己的配置文件/etc/nslcd.conf配置LDAP的访问参数。而且,nslcd.conf 的
预设map可以正常使用(即用RFC2307预设标准:ou=people对应用户, ou=Groups对应群组),
因此,您无需在/etc/nslcd.conf文档中手工配置nss_base_passwd和nss_base_group等映射,
除非您的LDAP数据库本身使用了非RFC2307标准的用户结构。

因此,要使用 nslcd 服务,还需要针对LDAP服务器进行配置, 使用 authconfig-tui 命令
也会自动配置 nslcd 的配置文件(/etc/nslcd.conf)。而 nscd 只有通用的缓存定义的配置,
一般情况下无需调整其配置文件(/etc/nscd.conf)。

注意,nslcd 并没有缓存的功能,它是专门为本地处理有关 LDAP 名称服务查询的后台进程,
查询结果依然由 nscd 缓存。(This package provides a daemon for retrieving user
account, and other system information from LDAP. It is used by the libnss-ldapd
and libpam-ldapd packages but by itself is not very useful)。

man nscd;
--------------------------------------------------------------------------------
/usr/sbin/nscd - name service cache daemon

Nscd is a daemon that provides a cache for the most common name service requests.
Default configuration /etc/nscd.conf determines the behavior of the cache daemon.

Nscd provides caching for: passwd, group, hosts databases through standard libc
interfaces (getpwnam, getpwuid, getgrnam, getgrgid, gethostbyname, and others).

There are two caches for each database:
  * a positive one for items found, and
  * a negative one for items not found. 

Each cache has a separate TTL (time-to-live) period for its data.
Note that the shadow file is specifically not cached.
--------------------------------------------------------------------------------

因此,您可以停止 nscd 进程,这样相关查询会自动绕过缓存,直接向相关的名称服务递交
查询请求(例如关于LDAP的查询请求则会直接查询nslcd后端进程)。 但是,如果您停止了
nslcd后台进程,如果相关记录的TTL又已经到期了,那么查询就会返回错误的结果。在默认
的设置下,密码的 positive-time-to-live 设为600秒,negative-time-to-live则为20秒。

如果修改了/etc/nsswitch.conf文件,相关影响会稍为延后才起作用,但您可以用如下命令
令nscd后台进程立即无效化其缓存记录,例如: nscd -i passwd;  您也可以直接删除缓存

/var/cache/nscd(或/var/db/nscd) 目录下的数据库文件,然后重启nscd后台守护进程即可。

 




────────────────────────────────────────────────────────────────────────────────
注意:sssd 与 nscd 的冲突
────────────────────────────────────────────────────────────────────────────────
另外请留意,新版RedHat/CentOS默认改为使用SSSD来处理有关系统安全服务的名称查询请求,
因为sssd服务本身已经具备缓存的功能,因此可以不使用nscd后台进程(重复缓存并无好处)。
如果同时启动nscd服务,那么sssd启动时会提示警告信息如下:

  Starting sssd: nscd socket was detected.  As nscd caching capabilities may
  conflict with SSSD, it is recommended to not run nscd in parallel with SSSD
或者在 /var/log/messages 日志中显示如下信息:
  sssd: nscd socket was detected. Nscd caching capabilities may conflict with SSSD
  for users and groups. It is recommended not to run nscd in parallel with SSSD,
  unless nscd is configured not to cache the passwd, group and netgroup nsswitch maps.

在sssd.conf的说明中,默认的 entry_cache_timeout=5400(秒),但是,在CentOS中默认
安装下所配置的sssd服务并没有启用记录条目的缓存功能(设成entry_cache_timeout = 0)。
Password caching for offline supporting by specifying "cache_credentials = True"
in sssd.conf. If config file uses that option, offline logins should just work.
RedHat官方建议关闭nscd服务进程,但在实用中发现 sssd 实在是问题多多,或许还是按照
如下RedHat官方网站文档中的指示让这两个服务共存为好!


********************************************************************************
如下是RedHat官方的正式解释:
********************************************************************************
http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/usingnscd-sssd.html

10.2.9. Using NSCD with SSSD
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
SSSD is not designed to be used with the NSCD daemon. Even though SSSD does not
directly conflict with NSCD, using both services can result in unexpected behavior,
especially with how long entries are cached.

The most common evidence of a problem is conflicts with NFS. When using Network
Manager to manage network connections,   it may  take  several  minutes for the
network interface to come up. During this time, various services attempt to start.

If these services start before the network is up and the DNS servers are available,
these services will fail to identify the forward or reverse DNS entries they need.
These services will read an incorrect or possibly empty  /etc/resolv.conf  file.
This file is typically only read once, and so any changes made to this file are
not automatically applied.  This can cause NFS locking to fail on the machine
where the NSCD service is running, unless that service is manually restarted.

To avoid this problem, enable caching for hosts and services in the /etc/nscd.conf
file and rely on the SSSD cache for the passwd, group, and netgroup entries.

Change the /etc/nscd.conf file:
enable-cache hosts yes
enable-cache passwd no
enable-cache group no
enable-cache netgroup no

With NSCD answering hosts requests, these entries will be cached by NSCD and
returned by NSCD during the boot process. All other entries are handled by SSSD.


注意:事实上nscd目前只支持缓存四种名称服务: passwd, group, hosts, services,而且
新版的nscd配置文件有点古怪的地方,如果您想注释一行,您一定必须将 “#” 添加在最前面
一列,而不能在前面带任何空格或tab分栏,否则重启nscd服务会遇到failed to start问题。

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



────────────────────────────────────────────────────────────────────────────────
如何查看当前系统的身份认证配置模式?
────────────────────────────────────────────────────────────────────────────────
在RedHat系统中可以使用authconfig命令查看当前的认证模式配置,例如:
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
authconfig --test | egrep -i 'ldap|sss'
authconfig --test | egrep -i 'ldap|sss|pam|nss'
--------------------------------------------------------------------------------
nss_files is always enabled
nss_compat is disabled
nss_db is disabled
nss_hesiod is disabled
nss_ldap is disabled
 LDAP+TLS is disabled
 LDAP server = "ldap://192.168.56.1/"
 LDAP base DN = "dc=hung,dc=moon,dc=com"
nss_nis is disabled
nss_nisplus is disabled
nss_winbind is disabled
nss_sss is enabled by default
nss_wins is disabled
DNS preference over NSS or WINS is disabled
pam_unix is always enabled
pam_krb5 is disabled
pam_ldap is disabled
 LDAP+TLS is disabled
 LDAP server = "ldap://192.168.56.1/"
 LDAP base DN = "dc=hung,dc=moon,dc=com"
 LDAP schema = "rfc2307"
pam_pkcs11 is disabled
pam_fprintd is enabled
pam_smb_auth is disabled
pam_winbind is disabled
pam_sss is enabled by default
 credential caching in SSSD is enabled
 SSSD use instead of legacy services if possible is enabled
pam_cracklib is enabled (try_first_pass retry=3 type=)
pam_passwdqc is disabled ()
pam_access is disabled ()
pam_mkhomedir or pam_oddjob_mkhomedir is disabled ()
--------------------------------------------------------------------------------


在Debian/Ubuntu系统中则可使用auth-client-config工具查看当前的NSS和PAM配置,例如:
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
auth-client-config -S
--------------------------------------------------------------------------------
nss_group=group:          compat
nss_netgroup=netgroup:       nis
nss_passwd=passwd:         compat
nss_shadow=shadow:         compat
pam_account=account [success=2 new_authtok_reqd=done default=ignore] pam_unix.so 
account [success=1 default=ignore] pam_ldap.so 
account requisite pam_deny.so
account required pam_permit.so
pam_auth=auth [success=2 default=ignore] pam_unix.so nullok_secure
auth [success=1 default=ignore] pam_ldap.so use_first_pass
auth requisite pam_deny.so
auth required pam_permit.so
auth optional pam_cap.so
pam_password=password requisite pam_cracklib.so retry=3 minlen=8 difok=3
password [success=2 default=ignore] pam_unix.so obscure use_authtok try_first_pass sha512
password [success=1 user_unknown=ignore default=die] pam_ldap.so use_authtok try_first_pass
password requisite pam_deny.so
password required pam_permit.so
password optional pam_gnome_keyring.so
pam_session=session [default=1] pam_permit.so
session requisite pam_deny.so
session required pam_permit.so
session optional pam_umask.so
session required pam_unix.so 
session optional pam_ldap.so 
session optional pam_ck_connector.so nox11
--------------------------------------------------------------------------------

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值