The NoteBook of EricKong

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

          輕量級目錄訪問協(xié)議 (Lightweight Directory Access Protocol,LDAP) 是一個輕量級的客戶機-服務(wù)器協(xié)議,用于訪問目錄服務(wù),尤其是那些基于 X.500 的服務(wù)。IBM Directory Server 是一個實現(xiàn) LDAP 協(xié)議的成熟產(chǎn)品。近來流行的 Linux 提供了一些系統(tǒng)用戶驗證方法,包括本地文件、NIS、LDAP 和 PAM 機制。Linux 可以為不同的服務(wù)使用不同的驗證方法。

          本文介紹了如何使用 IBM Directory Server 進行 Linux 用戶驗證。我沒有在文中介紹相關(guān)的概念; 參考資料 中有相關(guān)的背景資料。

          我要管理的 Linux 系統(tǒng)為 RedHat Linux 7.3,LDAP 服務(wù)器是 IBM Directory Server 5.1。如果需要,請參考 RedHat 和 IBM 的網(wǎng)站提供的 Linux 和 Directory Server 5.1 安裝說明。




          配置 Directory Server 5.1 服務(wù)器

          在使用 Directory Server 來存儲您的 Linux 系統(tǒng)用戶信息之前,您需要先計劃您的系統(tǒng)用戶結(jié)構(gòu)。例如,我將 Directory Server 5.1 服務(wù)器安裝在一個單獨的 Windows 2000 服務(wù)器上,計劃了如下的系統(tǒng)用戶結(jié)構(gòu):

          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




          使用以下步驟來構(gòu)建這個結(jié)構(gòu):

          添加后綴。停止 Directory Server 服務(wù)器,然后使用 ldapxcfg 添加一個新的后綴: o=ibm,c=cn ,參見 圖 1
          圖 1. 添加一個新后綴




          Click here to open new window

          導(dǎo)入 LDAP Data Interchange Format (LDIF) 文件,以及基本結(jié)構(gòu)。編輯 LDIF 文件,它定義了根專有名稱 (distinguished name,DN) 和基本結(jié)構(gòu) 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 導(dǎo)入 LDIF,參見 圖 2。




          Click here to open new window

          使用 Web 工具 ldif2db 來添加用戶。創(chuàng)建一個新用戶條目有兩種不同的方法:
          Web 工具
          Directory Server 5.1 提供了一個 Web 應(yīng)用程序,可以部署到特定的應(yīng)用程序服務(wù)器上。它默認(rèn)使用 WebSphere Application Server 5.0 express。這個工具為用戶提供了一個友好的界面來幫您管理 LDAP 信息。
          命令行工具
          使用 ldif2db 來導(dǎo)入條目。例如,
          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 用戶信息,對象類應(yīng)該是 posixAccount 。將本條目的 entryowner 設(shè)置為用戶“自己”,這樣用戶就可以修改密碼。要了解更多關(guān)于 Directory Server ACL 的信息,請閱讀 Directory Server 文檔。

          添加用戶完成后,啟動 Directory Server 服務(wù)器來開始為 Linux 用戶驗證服務(wù)。




          Linux 上的配置

          在 RedHat Linux 7.3 上,以 root 身份登錄,確保已經(jīng)安裝了以下兩個軟件包:

          openldap-2.0.23-4
          nss_ldap-185-1
          使用 #rpm -qa|grep ldap 命令來檢查已安裝的 RPM。如果沒有安裝這兩個軟件包,那么掛載 RedHat 安裝映像并執(zhí)行以下命令:
          #rpm -ivh /openldap-2.0.23-4.rpm
          #rpm -ivh /nss_ldap-185-1.rpm

          兩個軟件包安裝完成后,打開 /etc/ldap.conf 文件來做一些配置。下面是一些用于配置的關(guān)鍵指令。 host 指定 LDAP 服務(wù)器 IP/主機名
          base 指定 LDAP 客戶機搜索起點
          port 指定 LDAP 服務(wù)器端口
          pam_filter 指定 LDAP 客戶機搜索過濾器
          pam_login_attribute 指定一個用戶條目的登錄屬性
          pam_password 指定客戶機密碼哈希方法


          下面的例子是 ldap.conf 文件的部分內(nèi)容。尤其注意那些 加粗的指令。


          # @(#)$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 驗證,即執(zhí)行 #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 系統(tǒng)將開始啟用 LDAP 驗證。
          這個工具將會把指令 pam_password 的值設(shè)置為 md5。為了讓用戶可以成功地修改密碼,您需要手工將這個指令值設(shè)置為“clear”。

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




          Click here to open new window

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





          現(xiàn)在再次以 user1 身份登錄,不再出現(xiàn)警告:




          Click here to open new window

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

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

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 天长市| 扶绥县| 且末县| 乌拉特前旗| 田东县| 西畴县| 吉木乃县| 荔波县| 江源县| 海口市| 营山县| 西畴县| 来凤县| 永福县| 威远县| 渝北区| 咸丰县| 霍邱县| 河间市| 玛沁县| 周至县| 德安县| 郴州市| 东台市| 房产| 桂林市| 石楼县| 南溪县| 隆化县| 蒙自县| 土默特右旗| 阜新| 南昌市| 广元市| 新和县| 霍林郭勒市| 龙岩市| 永嘉县| 常山县| 东辽县| 清流县|