8. 设置 NIS+ 需要什么?

8.1. 软件

Linux NIS+ 客户端代码是为 GNU C 库 2 开发的。还有一个针对 Linux libc5 的移植版本,因为过去大多数商业应用程序都是链接到这个库的,并且您无法为了使用 glibc 而重新编译它们。libc5 和 NIS+ 存在问题:静态程序无法与其链接,并且使用此库编译的程序将无法与其他 libc5 版本一起使用。

作为基础系统,您需要像 Debian、Red Hat Linux 或 SuSE Linux 这样基于 glibc 的发行版。如果您的 Linux 发行版没有 glibc 2.1.1 或更高版本,则需要更新到较新版本。

可以从以下位置获取 NIS+ 客户端软件
  Site             Directory                     File Name

  ftp.gnu.org     /pub/gnu/glibc                 glibc-2.3.2.tar.gz,
                                                 glibc-linuxthreads-2.3.2.tar.gz
  ftp.kernel.org   /pub/linux/utils/net/NIS+     nis-utils-1.4.1.tar.gz

您还应该查看 http://www.linux-nis.org/nisplus/ 以获取更多信息和最新源代码。

8.2. 设置 NIS+ 客户端

重要提示:要设置 NIS+ 客户端,请阅读您的 Solaris NIS+ 文档,了解服务器端需要做什么!本文档仅描述客户端需要做什么!

安装新的 libc 和 nis-tools 后,在 NIS+ 服务器上为新客户端创建凭据。确保 portmap 正在运行。然后检查您的 Linux PC 的时间是否与 NIS+ 服务器的时间相同。对于安全的 RPC,您只有一个大约 3 分钟的小窗口,凭据在此窗口内有效。一个好主意是在每台主机上运行 xntpd。完成这些后,运行

domainname nisplus.domain.
nisinit -c -H <NIS+ server>

以初始化冷启动文件。阅读 nisinit 手册页以获取更多选项。确保域名在重启后始终设置。如果您不知道网络上的 NIS+ 域名是什么,请咨询您的系统/网络管理员。

现在您应该更改您的/etc/nsswitch.conf文件。确保 publickey 之后的唯一服务是 nisplus ("publickey: nisplus"),没有其他服务!

然后启动 keyserv 并确保它始终在启动时作为 portmap 之后的第一个守护程序启动。运行
keylogin -r
以在您的系统上存储 root secretkey。(我希望您已在 NIS+ 服务器上为新主机添加了 publickey?)。

niscat passwd.org_dir 现在应该向您显示 passwd 数据库中的所有条目。

8.3. NIS+、keylogin、login 和 PAM

当用户登录时,他需要将他的 secretkey 设置到 keyserv。这可以通过调用 "keylogin" 来完成。如果 shadow 包中的 login 是针对 glibc 2.1 编译的,它将为用户执行此操作。对于 PAM 感知的登录,您必须更改 /etc/pam.d/login 文件以使用 pam_unix2,而不是 pwdb,后者不支持 NIS+。一个例子

#%PAM-1.0
auth       required	/lib/security/pam_securetty.so
auth       required	/lib/security/pam_unix2.so       set_secrpc
auth       required	/lib/security/pam_nologin.so
account    required	/lib/security/pam_unix2.so
password   required	/lib/security/pam_unix2.so
session    required	/lib/security/pam_unix2.so

8.4. nsswitch.conf 文件

网络服务交换文件/etc/nsswitch.conf确定在请求特定信息时执行查找的顺序,就像/etc/host.conf文件一样,该文件确定主机查找的执行方式。例如,行

    hosts: files nisplus dns

指定主机查找功能应首先在本地/etc/hosts文件中查找,然后是 NIS+ 查找,最后通过域名服务(/etc/resolv.conf和 named),如果在此时未找到匹配项,则返回错误。

一个好的/etc/nsswitch.confNIS+ 的文件是
#
# /etc/nsswitch.conf
#
# An example Name Service Switch config file. This file should be
# sorted with the most-used services at the beginning.
#
# The entry '[NOTFOUND=return]' means that the search for an
# entry should stop if the search in the previous entry turned
# up nothing. Note that if the search failed due to some other reason
# (like no NIS server responding) then the search continues with the
# next entry.
#
# Legal entries are:
#
#	nisplus			Use NIS+ (NIS version 3)
#	nis			Use NIS (NIS version 2), also called YP
#	dns			Use DNS (Domain Name Service)
#	files			Use the local files
#	db			Use the /var/db databases
#	[NOTFOUND=return]	Stop searching if not found so far
#

passwd:     compat
group:      compat
shadow:     compat

passwd_compat: nisplus
group_compat:  nisplus
shadow_compat: nisplus

hosts:      nisplus files dns

services:   nisplus [NOTFOUND=return] files
networks:   nisplus [NOTFOUND=return] files
protocols:  nisplus [NOTFOUND=return] files
rpc:        nisplus [NOTFOUND=return] files
ethers:     nisplus [NOTFOUND=return] files
netmasks:   nisplus [NOTFOUND=return] files
netgroup:   nisplus
bootparams: nisplus [NOTFOUND=return] files
publickey:  nisplus
automount:  files
aliases:    nisplus [NOTFOUND=return] files