歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> 使用IBM目錄服務進行Linux用戶驗證

使用IBM目錄服務進行Linux用戶驗證

日期:2017/2/27 9:21:16   编辑:更多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描述了此產品的所有亮點。




Copyright © Linux教程網 All Rights Reserved