当前位置:Linux教程 - Linux资讯 - 使用IBM目录服务进行Linux用户验证

使用IBM目录服务进行Linux用户验证

简介

轻量级目录访问协议 (Lightweight Directory Access Protocol,LDAP) 是一个轻量级的客户机-服务器协议,用于访问目录服务,尤其是那些基于 X.500 的服务。IBM Directory Server 是一个实现 LDAP 协议的成熟产品。近来流行的 Linux 提供了一些系统用户验证方法,包括本地文件、NIS、LDAP 和 PAM 机制。Linux 可以为不同的服务使用不同的验证方法。

本文介绍了如何使用 IBM Directory Server 进行 Linux 用户验证。我没有在文中介绍相关的概念; 参考资料 中有相关的背景资料。

我要管理的 Linux 系统为 RedHat Linux 7.3,LDAP 服务器是 IBM Directory Server 5.1。如果需要,请参考 RedHat 和 IBM 的网站提供的 Linux 和 Directory Server 5.1 安装说明。

配置 Directory Server 5.1 服务器

在使用 Directory Server 来存储您的 Linux 系统用户信息之前,您需要先计划您的系统用户结构。例如,我将 Directory Server 5.1 服务器安装在一个单独的 windows 2000 服务器上,计划了如下的系统用户结构:

o=ibm,c=cn -ou=csdl,o=ibm,c=cn -ou=gcl,ou=csdl,o=ibm,c=cn -uid=user1,ou=gcl,ou=csdl,o=ibm,c=cn -uid=user2,ou=gcl,ou=csdl,o=ibm,c=cn

使用以下步骤来构建这个结构:

添加后缀。停止 Directory Server 服务器,然后使用 ldapxcfg 添加一个新的后缀: o=ibm,c=cn ,参见 图 1 图 1. 添加一个新后缀 点击查看大图 导入 LDAP Data Interchange Format (LDIF) 文件,以及基本结构。编辑 LDIF 文件,它定义了根专有名称 (distinguished name,DN) 和基本结构 DN,如下所示。

version: 1 dn: o=IBM,c=CN objectclass: top objectclass: organization o: ibm dn: ou=CSDL,o=ibm,c=cn ou: CSDL objectclass: organizationalUnit objectclass: top description: China Software Development Lab businessCategory: R&D dn: ou=GCL,ou=CSDL,o=ibm,c=cn ou: GCL objectclass: organizationalUnit objectclass: top description: Globalization Certification Lab

使用 ldapxcfg 导入 LDIF,参见 图 2。

图 2. 使用 Web 工具 ldif2db 来添加用户。创建一个新用户条目有两种不同的方法: Web 工具 Directory Server 5.1 提供了一个 Web 应用程序,可以部署到特定的应用程序服务器上。它默认使用 WebSphere Application Server 5.0 eXPress。这个工具为用户提供了一个友好的界面来帮您管理 LDAP 信息。 命令行工具 使用 ldif2db 来导入条目。例如, ldif2db -i oneEntry.ldif

下面的这个例子介绍了如何使用命令工具来添加一个新用户。

#oneEntry.ldif dn: uid=user1,ou=GCL,ou=CSDL,o=ibm,c=cn loginShell: /bin/bash memberUid: 900 gidNumber: 800 objectclass: posixGroup objectclass: top objectclass: posixAccount objectclass: shadowAccount uid: user1 uidNumber: 900 cn: user1 description: One user of system homeDirectory: /home/user1 userpassWord: password ownerpropagate: TRUE entryowner: access-id:UID=USER1,OU=GCL,OU=CSDL,O=IBM,C=CN

对于 Linux 用户信息,对象类应该是 posixAccount 。将本条目的 entryowner 设置为用户“自己”,这样用户就可以修改密码。要了解更多关于 Directory Server ACL 的信息,请阅读 Directory Server 文档。

添加用户完成后,启动 Directory Server 服务器来开始为 Linux 用户验证服务。

Linux 上的配置

在 RedHat Linux 7.3 上,以 root 身份登录,确保已经安装了以下两个软件包: openldap-2.0.23-4 nss_ldap-185-1 使用 #rpm -qagrep ldap 命令来检查已安装的 RPM。如果没有安装这两个软件包,那么挂载 RedHat 安装映像并执行以下命令:

#rpm -ivh <PathToPkgs>/openldap-2.0.23-4.rpm #rpm -ivh <PathToPkgs>/nss_ldap-185-1.rpm

两个软件包安装完成后,打开 /etc/ldap.conf 文件来做一些配置。下面是一些用于配置的关键指令。 host 指定 LDAP 服务器 IP/主机名 base 指定 LDAP 客户机搜索起点 port 指定 LDAP 服务器端口 pam_filter 指定 LDAP 客户机搜索过滤器 pam_login_attribute 指定一个用户条目的登录属性 pam_password 指定客户机密码哈希方法

下面的例子是 ldap.conf 文件的部分内容。尤其注意那些 加粗的指令。

# @(#)$Id: ldap.conf,v 1.24 2001/09/20 14:12:26 lukeh Exp $ # # This is the configuration file for the LDAP nameservice # switch library and the LDAP PAM module. # # PADL Software # http://www.padl.com # # Your LDAP server. Must be resolvable without using LDAP. #host 127.0.0.1 host 192.168.0.188 # The distinguished name of the search base. #base dc=example,dc=com base o=IBM,c=CN # Another way to specify your LDAP server is to provide an # uri with the server name. This allows to use # Unix Domain Sockets to connect to a local LDAP Server. #uri ldap://127.0.0.1/ #uri ldaps://127.0.0.1/ #uri ldapi://%2fvar%2frun%2fldapi_sock/ # Note: %2f encodes the '/' used as directory separator # The LDAP version to use (defaults to 3 # if supported by client library) #ldap_version 3 # The distinguished name to bind to the server with. # Optional: default is to bind anonymously. #binddn cn=proxyuser,dc=example,dc=com # The credentials to bind with. # Optional: default is no credential. # The distinguished name to bind to the server with # if the effective user ID is root. Password is # stored in /etc/ldap.secret (mode 600) #rootbinddn cn=manager,dc=example,dc=com # The port. # Optional: default is 389. port 389 # The search scope. #scope sub #scope one #scope base # Search timelimit #timelimit 30 # Bind timelimit #bind_timelimit 30 # Idle timelimit; client will close connections # (nss_ldap only) if the server has not been contacted # for the number of seconds specified below. #idle_timelimit 3600 # Filter to AND with uid=%s pam_filter objectclass=posixAccount # The user ID attribute (defaults to uid) pam_login_attribute uid # Search the root DSE for the password policy (works # with Netscape Directory Server) #pam_lookup_policy yes # Check the 'host' attribute for access control # Default is no; if set to yes, and user has no # value for the host attribute, and pam_ldap is # configured for account management (authorization) # then the user will not be allowed to login. #pam_check_host_attr yes # Group to enforce membership of #pam_groupdn cn=PAM,ou=Groups,dc=example,dc=com # Group member attribute #pam_member_attribute uniquemember # Specify a minium or maximum UID number allowed #pam_min_uid 0 #pam_max_uid 0 # Template login attribute, default template user # (can be overriden by value of former attribute # in user's entry) #pam_login_attribute userPrincipalName #pam_template_login_attribute uid #pam_template_login nobody # HEADS UP: the pam_crypt, pam_nds_passwd, # and pam_ad_passwd options are no # longer supported. # Do not hash the password at all; presume # the directory server will do it, if # necessary. This is the default. #pam_password md5 pam_password clear ssl no ... ...

保存所作的修改,然后使用 authconfig 来启用 LDAP 验证,即执行 #authconfig 。

在 User Information Configuration 面板中,参见 图 3,选中 Cache Information和 Use LDAP。

图 3. User Information Configuration 点击查看大图

在 Authentication Configuration 面板中,选中 Use LDAP Authentication,参见 图 4。

图 4. Authentication Configuration 点击查看大图 然后输入 Ok。Linux 系统将开始启用 LDAP 验证。

这个工具将会把指令 pam_password 的值设置为 md5。为了让用户可以成功地修改密码,您需要手工将这个指令值设置为“clear”。

现在我们可以作为信息存储在 Directory Server 服务器上的用户来登录了。例如,以 user1 的身份登录:

因为没有 user1 的主目录,所以登录 shell 自动将目录切换到“/”。为方便起见我们可以手工添加用户主目录:

#mkdir /home/user1 #cp /etc/skel/.* /home/user1 #chown -R user1:user1 /home/user1

现在再次以 user1 身份登录,不再出现警告:

OK,好极了! 我们已经实现了一个基本的配置,可以利用 Directory Server 来对 Linux 系统用户进行验证。因为 Linux 和 Directory Server 都支持 Secure Sockets Layer (SSL),所以我们可以做更深入的配置以提高系统的安全性。关于 SSL 配置的更多信息,请参阅 参考资料。

参考资料

您可以参阅本文在 developerWorks 全球站点上的 英文原文. 请在 讨论论坛上参与本文的讨论。(您可以单击文章顶部或底部的 讨论来访问论坛。) 关于 LDAP 的介绍,请参阅 LDAP HowTo。 访问 LDAP Implementation HowTo可以得到关于 LDAP 验证对 Linux 支持的介绍。 要学习 Linux 系统用户验证机制,请参阅 User authentication HowTo。 IBM Directory Server library有关于 IBM Directory Server 5.1 的产品手册。 用户迁移工具 提供了一系列基于 Perl 的脚本,可以将 Linux 上的当前服务用户迁移到 LDAP 服务器上。 IBM Directory Server描述了此产品的所有亮点。

(出处:http://www.sheup.com)