The NoteBook of EricKong

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            611 Posts :: 1 Stories :: 190 Comments :: 0 Trackbacks
          簡介

          輕量級目錄訪問協議 (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. 添加一個新后綴




          Click here to open new window

          導入 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。




          Click here to open new window

          使用 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 -qa|grep ldap 命令來檢查已安裝的 RPM。如果沒有安裝這兩個軟件包,那么掛載 RedHat 安裝映像并執行以下命令:
          #rpm -ivh /openldap-2.0.23-4.rpm
          #rpm -ivh /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




          Click here to open new window

          在 Authentication Configuration 面板中,選中 Use LDAP Authentication,參見 圖 4。


          圖 4. Authentication Configuration




          Click here to open new window

          然后輸入 Ok。Linux 系統將開始啟用 LDAP 驗證。
          這個工具將會把指令 pam_password 的值設置為 md5。為了讓用戶可以成功地修改密碼,您需要手工將這個指令值設置為“clear”。

          現在我們可以作為信息存儲在 Directory Server 服務器上的用戶來登錄了。例如,以 user1 的身份登錄:




          Click here to open new window

          因為沒有 user1 的主目錄,所以登錄 shell 自動將目錄切換到“/”。為方便起見我們可以手工添加用戶主目錄:
          #mkdir /home/user1
          #cp /etc/skel/.* /home/user1
          #chown -R user1:user1 /home/user1





          現在再次以 user1 身份登錄,不再出現警告:




          Click here to open new window

          OK,好極了! 我們已經實現了一個基本的配置,可以利用 Directory Server 來對 Linux 系統用戶進行驗證。因為 Linux 和 Directory Server 都支持 Secure Sockets Layer (SSL),所以我們可以做更深入的配置以提高系統的安全性。

          posted on 2013-10-31 09:45 Eric_jiang 閱讀(297) 評論(0)  編輯  收藏 所屬分類: LDAP

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 鄂伦春自治旗| 宜阳县| 新野县| 舟曲县| 银川市| 宣恩县| 张掖市| 二连浩特市| 通江县| 北宁市| 海口市| 静乐县| 曲阜市| 隆林| 灵宝市| 广元市| 象州县| 深水埗区| 义乌市| 阿鲁科尔沁旗| 县级市| 高密市| 郑州市| 永康市| 五大连池市| 简阳市| 三明市| 东乌珠穆沁旗| 开鲁县| 陕西省| 闵行区| 古浪县| 竹山县| 巴楚县| 绩溪县| 河南省| 都江堰市| 丰宁| 阿巴嘎旗| 眉山市| 高雄市|