# numEntries: 1
(4) 利用LDIF文件添加数据
----------------------------------------------------------------------------------
LDAP中使用的数据格式是二进制格式,但是一个名为 LDAP Data Interchange Format(LDIF)
的ASCII序列化格式的文件, 可用于向LDAP数据库导出和导入数据. LDAP的LDIF文件必須使用
UTF-8編碼格式, 它的二进制数据被表示为base64编码.
OpenLDAP中包含系列工具:
ldapsearch 向LDAP服務器查詢的命令(用-L參數可将数据导出為LDIF文件);
ldapadd 将数据从LDIF导入到LDAP服务器;
ldapmodify 将LDIF中描述的一组更改应用到LDAP服务器(同ldapadd類似).
ldapdelete
此外,LDIF是用于为 Mozilla Application Suite 和其他用户应用程序级别的工具导入和
导出地址簿数据的格式之一, 甚至Microsoft Windows 2000 Server和Windows Server 2003
也包含一个LDIF工具(LDIFDE),用于向 Active Directory 导入和导出数据。
【ldapadd】添加節點:
-x 表示密碼驗證;
-D <DN> 指定管理員的DN;
-w <PASSWORD> 指定管理員的密碼;
-W 提示輸入管理員的密碼;
-f <FILE> 指定LDIF文件路徑;
-H <URL> 指定LDAP服務器的URL(例如本機為 ldap://localhost/);
要向LDAP服务器手动添加信息,首先要创建一个LDIF文件. 必須注意LDAP是樹狀結構的數據庫,
每棵目錄樹都必須由一個根(root)項目開始,其后所添加的分支節點的dn就必須對應此根項目
的dn內容來擴展. 如果您所添加的節點還沒有根節點, 或者沒有上層的父節點,那么就不可能
添加成功的. 如下是一個LDIF范例文件,它定義了一個根節點:
vim /tmp/test.ldif; #這是一個簡單的根定義;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
dn: dc=hung,dc=mooo,dc=com
objectClass: top
objectClass: dcObject
objectClass: organization
o: Testing Domain
description: This is my testing Openldap
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
請注意: 數據格式須正確才能加入(dn必須唯一). 可用如下命令將该文件導入到LDAP數據庫:
ldapadd -x -D "cn=admin,dc=hung,dc=mooo,dc=com" -W -f /tmp/test.ldif;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Enter LDAP Password:
adding new entry "dc=hung,dc=mooo,dc=com"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
vim /tmp/example.ldif; #這是一個測試文件(在當前根下添加兩個子節點);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
dn: dc=example,dc=hung,dc=mooo,dc=com
objectClass: dcObject
objectClass: organization
dc: example
o: Example Company
description: Corporation
dn: cn=Manager,dc=hung,dc=mooo,dc=com
objectClass: organizationalRole
cn: Manager
description: Directory Manager
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
請注意: 上述范例原文是example.com,在這里用一个适合本站的域(example.hung.mooo.com)
來取代它。通常LDAP域层次结构和名称与熟悉的DNS名称中使用的层次结构和名称匹配.
ldapadd -x -D "cn=admin,dc=hung,dc=mooo,dc=com" -W -f /tmp/example.ldif;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Enter LDAP Password:
adding new entry "dc=example,dc=hung,dc=mooo,dc=com"
adding new entry "cn=Manager,dc=hung,dc=mooo,dc=com"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
請注意: 上述導入過程需要寫入數據庫, 所以會提示您輸入管理員的密碼(用-W參數提示密碼),
這個密碼就是前述的slapd.conf中指定的rootpw值(Debian中好像不設置此值也一樣提示密碼).
另外,也可以用 -w password 連同密碼一起輸入命令中.
【ldapsearch】 測試查詢上述三個記錄:
ldapsearch -x -b 'dc=hung,dc=mooo,dc=com' -s base '(objectclass=*)'
ldapsearch -x -b 'dc=example,dc=hung,dc=mooo,dc=com' -s base '(objectclass=*)'
ldapsearch -x -b 'cn=Manager,dc=hung,dc=mooo,dc=com' -s base '(objectclass=*)'
ldapsearch -x -b 'dc=hung,dc=mooo,dc=com' '(objectclass=*)'; #顯示整棵樹;
ldapsearch -x -b 'dc=hung,dc=mooo,dc=com' -s sub '(objectclass=*)'; #(同上);
ldapsearch -x -b 'dc=hung,dc=mooo,dc=com' '(objectclass=*)' -L; #按LDIF格式顯示;
ldapsearch -x -b 'dc=hung,dc=mooo,dc=com' '(objectclass=*)' -LL;
ldapsearch -x -b 'dc=hung,dc=mooo,dc=com' '(objectclass=*)' -LLL;
【ldapdelete】
ldapdelete "cn=Manager,dc=hung,dc=mooo,dc=com" -x -W \
-D "cn=admin,dc=hung,dc=mooo,dc=com"; #刪除節點;
ldapdelete -n "dc=example,dc=hung,dc=mooo,dc=com" -x -W \
-D "cn=admin,dc=hung,dc=mooo,dc=com"; #嘗試刪除節點但不是真正刪除;
【常見問題】
如果是在Windows上編好LDIF檔之後再傳到主機上的話可能會遇到每行后面多了^M字元的問題,
必須將這些字元清除,Unix/Linux系統下有個格式轉換工具dos2unix,可以達到這個目的,例如:
apt-get install tofrodos; #需先安裝此套件;
dos2unix -b my.dos.ldif; #參數-b指定備份原文件(所備份的文件為 原文件名.bak);
因為LDAP就規定了LDIF文件必須要使用UTF-8格式,所以如果您的LDIF是其他格式的文件,那就
必須先轉換成UTF-8格式,可以用iconv命令來做這件事,例如:
iconv -f big5 -t UTF-8 -o my.ldif.utf8 my.big5.ldif;
iconv -f gb2312 -t UTF-8 -o my.ldif.utf8 my.gb2312.ldif;
(5) OpenLDAP的應用(導入現有的帳號資料)
----------------------------------------------------------------------------------
對于網絡管理員來說,LDAP最經常的用途是作為多種服務器共同的帳號數據庫. OpenLDAP非常
適合于用來統籌管理帳號信息, 讓管理員只做一次增加,刪除和修改等動作, 就可應用于整個
組織.
【引入所需模式】
要讓LDAP目錄能儲存帳號信息,還必須引入(include)具有合適對象類別的模式(schema),例如
要想使用原本儲存于/etc/passwd和/etc/shadow文件中的帳號,就必須先引入nis.schema模式,
因為該模式提供了posixAccount和shadowAccount兩個對象類(objectClass),可用以滿足上述
要求. 此外, 如果還想要儲存全公司通用的用戶帳號, 你還需要cosine.schema模式所定義的
account對象類. 檢查并修正前述的/etc/ladp/slapd.conf配置文件,確認包含如下選項:
cat /etc/ldap/slapd.conf; #帳號管理所需的模式等配置;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
include /etc/ldap/schema/cosine.schema
include /etc/ldap/schema/nis.schema
index cn,uid eq
index uidNumber eq
index gidNumber eq
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(注: 可用egrep過濾查詢命令: cat /etc/ldap/slapd.conf | egrep '^index|^include';)
請注意: 上述三個索引(index)的作用是提高搜索速度.
【轉換現有的帳號數據】
PADL軟件公司提供了一組轉換工具,可從現有的/etc/passwd和/etc/shadow文件中取得數據并
將之轉換成LDIF格式的文件. 這個工具叫MigrationTools(一組Perl腳本),可從如下地址下載:
http://www.padl.com/OSS/MigrationTools.html
wget http://www.padl.com/download/MigrationTools.tgz;
tar zxvf MigrationTools.tgz;
cd MigrationTools-47/;
執行任何轉換任務之前,必須先編輯migrate_common.ph這個配置文件,以便將幾個重要的變數
設定成符合您的系統的實際情況. 需要修改的參數大概是如下幾個:
$DEFAULT_MAIL_DOMAIN 缺省的DNS域名;
$DEFAULT_BASE 缺省的基本域名(即根的域名);
$DEFAULT_MAIL_HOST 缺省的
vim ./migrate_common.ph; #如下是適用于我的系統的設置;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$DEFAULT_MAIL_DOMAIN = "hung.mooo.com";
$DEFAULT_BASE = "dc=hung,dc=mooo,dc=com";
$DEFAULT_MAIL_HOST = "mail.hung.mooo.com";
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
./migrate_passwd.pl /etc/passwd /tmp/passwd.ldif; #轉換passwd文件;
cat /tmp/passwd.ldif; #
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
dn: uid=root,ou=People,dc=hung,dc=mooo,dc=com
uid: root
cn: root
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword: {crypt}$1$pXy0ET57$QdbsSV0FGxcff80OjbZBQ/
shadowLastChange: 13814
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 0
gidNumber: 0
homeDirectory: /root
gecos: root
...(省略)...
dn: uid=testing,ou=People,dc=hung,dc=mooo,dc=com
uid: testing
cn: testing
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword: {crypt}cCiyk5hxetmRY
shadowLastChange: 13829
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 1002
gidNumber: 1002
homeDirectory: /home/testing
gecos: testing
...(省略)...
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
從上述LDIF數據可看出,因為這些節點都是定義在ou=People這個節點下面的:
cat /tmp/passwd.ldif | grep 'dn:'; #看看所有需添加的節點的dn內容;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
dn: uid=root,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=daemon,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=bin,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=sys,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=sync,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=games,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=man,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=lp,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=mail,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=news,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=uucp,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=proxy,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=www-data,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=backup,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=list,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=irc,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=gnats,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=nobody,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=Debian-exim,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=statd,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=identd,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=bind,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=sshd,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=named,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=apache,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=testing,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=openldap,ou=People,dc=hung,dc=mooo,dc=com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
如果在之前的操作中并未添加過這個節點的話, 那么就必須先產生這個節點. 當然您可以自己
手工來添加這個節點, 但是有一個更方便的做法, 就是利用MigrationTools這組工具中附帶的
一個Perl腳本來自動生成. 這個腳本及其使用方法請參考如下:
./migrate_base.pl > /tmp/people.ldif;
cat /tmp/people.ldif; #看看
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
dn: dc=mooo,dc=com
dc: mooo
objectClass: top
objectClass: domain
dn: dc=hung,dc=mooo,dc=com
dc: hung
objectClass: top
objectClass: domain
...(省略)...
dn: ou=People,dc=hung,dc=mooo,dc=com
ou: People
objectClass: top
objectClass: organization**it
dn: ou=Group,dc=hung,dc=mooo,dc=com
ou: Group
objectClass: top
objectClass: organization**it
...(省略)...
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
請注意: 在上述命令所創建的LDIF內容中,除了第一個和第二個節點通常可能因為系統中已經
存在或者格式不合, 因此不能導入LDAP數據庫之外,其他節點應該都是具有全新dn內容的節點.
如果是為了學習目的,建議您將上述LDIF文件的整個文件的內容都導入到LDAP數據庫中, 當然
如果您不愿意添加太多節點到您的LDAP數據庫中的話,也可以編輯上述文件的內容, 但至少要
包含其中的 ou=People,dc=hung,dc=mooo,dc=com 和 ou=Group,dc=hung,dc=mooo,dc=com 這
兩個節點, 因為這兩個節點就是下一個導入步驟(后面還需要轉換/etc/group文件)中將需要
的父節點. 導入命令參考如下:
ldapadd -x -D "cn=admin,dc=hung,dc=mooo,dc=com" -W -f /tmp/people.ldif;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Enter LDAP Password:
adding new entry "ou=People,dc=hung,dc=mooo,dc=com"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ldapsearch -x -b 'dc=hung,dc=mooo,dc=com' '(objectclass=*)' -LL; #看看所有樹節點;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
dn: dc=hung,dc=mooo,dc=com
objectClass: top
objectClass: dcObject
objectClass: organization
o: hung.mooo.com
dc: hung
dn: cn=admin,dc=hung,dc=mooo,dc=com
objectClass: simpleSecurityObject
objectClass: organizationalRole
cn: admin
description: LDAP administrator
dn: ou=People,dc=hung,dc=mooo,dc=com
ou: People
objectClass: top
objectClass: organization**it
dn: ou=Group,dc=hung,dc=mooo,dc=com
ou: Group
objectClass: top
objectClass: organization**it
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
請注意: 上述資料顯示現在ou=People和ou=Group這兩個節點已經添加進入LDAP數據庫中了;
ldapadd -x -D "cn=admin,dc=hung,dc=mooo,dc=com" -W -f /tmp/passwd.ldif;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Enter LDAP Password:
adding new entry "uid=root,ou=People,dc=hung,dc=mooo,dc=com"
adding new entry "uid=daemon,ou=People,dc=hung,dc=mooo,dc=com"
adding new entry "uid=bin,ou=People,dc=hung,dc=mooo,dc=com"
adding new entry "uid=sys,ou=People,dc=hung,dc=mooo,dc=com"
adding new entry "uid=sync,ou=People,dc=hung,dc=mooo,dc=com"
...(省略)...
adding new entry "uid=testing4,ou=People,dc=hung,dc=mooo,dc=com"
adding new entry "uid=openldap,ou=People,dc=hung,dc=mooo,dc=com"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
上述命令執行后的信息顯示,所有節點都添加成功了! 現在在看看LDAP數據庫的目錄樹:
ldapsearch -x -b 'dc=hung,dc=mooo,dc=com' '(objectclass=*)' -LL | grep 'dn:';
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
dn: dc=hung,dc=mooo,dc=com
dn: cn=admin,dc=hung,dc=mooo,dc=com
dn: ou=People,dc=hung,dc=mooo,dc=com
dn: uid=root,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=daemon,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=bin,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=sys,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=sync,ou=People,dc=hung,dc=mooo,dc=com
...(省略)...
dn: uid=testing4,ou=People,dc=hung,dc=mooo,dc=com
dn: uid=openldap,ou=People,dc=hung,dc=mooo,dc=com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
參考前述的轉換和導入步驟,將/etc/group文件也轉換并導入LDAP數據庫:
./migrate_group.pl /etc/group /tmp/group.ldif;
ldapadd -x -D "cn=admin,dc=hung,dc=mooo,dc=com" -W -f /tmp/group.ldif;
(6) 配置LDAP客戶端
----------------------------------------------------------------------------------
[1] 根據實際情況,您的LDAP客戶端可能需要安裝如下套件:
apt-get install ldap-utils;
apt-get install libldap2;
apt-get install libldap2-dev;
apt-get install libldap-2.3-0;
[2] 設置LDAP客戶端配置文件:
vim /etc/ldap/ldap.conf; #調整(或添加)如下最后三行;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
HOST 10.10.0.1 #這是新添加的行(其實這行可忽略);
BASE dc=hung, dc=mooo, dc=com #注意這里要修改(即指定根節點的dn);
URI ldap://10.10.0.1/ #這里可設置多臺LDAP服務器,用空格隔開即可;
#添加如下三行,后面配置nss_ldap來使用LDAP服務時將要調用(若不用nss_ldap則可忽略);
nss_base_passwd ou=People,dc=hung,dc=mooo,dc=com
nss_base_shadow ou=People,dc=hung,dc=mooo,dc=com
nss_base_group ou=Group,dc=hung,dc=mooo,dc=com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
請注意: 通常預設的ldap.conf文件都將BASE和URI注釋掉, 但如要啟動LDAP客戶端,則一定要
設置BASE和URI參數. 尤其是URI參數更為重要, 如果您有多臺LDAP服務器(如Master和Slave),
那么也可以在URI中設置多個ldap參數,以空格分隔即可,例如:
URI ldap://10.10.0.1/ ldap://10.10.1.1/ #這里設置了兩臺LDAP服務器;
[3] 現在可在客戶端測試LDAP服務器端的反應,例如在客戶端查詢LDAP服務器:
ldapsearch -x -b 'dc=hung,dc=mooo,dc=com' -h 10.10.0.1 '(objectclass=*)' -LL;
ldapsearch -x -b 'uid=testing4,ou=People,dc=hung,dc=mooo,dc=com' -LL;
如果執行上述命令之后,能夠返回LDAP服務器中的節點資料,說明LDAP客戶端已經成功連線并
能夠獲進行資料查詢了.
----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
(7) 在LDAP客戶端配置nss_ldap來使用LDAP服務器提供認證服務
----------------------------------------------------------------------------------
LDAP的客戶端應用非常廣泛, 而且不同的應用須對應不同的目錄樹, 最后還必須依照客戶端
軟件的具體特點, 來將其數據源改為LDAP服務器的數據庫. 下面介紹一個例子, 演示了如何
在客戶端配置Linux系統的NSS設置, 即通過nss_ldap來使用LDAP服務器, 以提供用戶登錄等
驗證服務.
[1] 安裝nss_ldap套件
在配置NSS啟用LDAP服務之前,首先要安裝libnss-ldap套件. 可以參考如下幾種方法來安裝和
配置libnss-ldap套件(分別適用于Debian和RedHat,以及Tarbll資源).
【在Debian系統中使用套件管理工具來安裝libnss-ldap套件】
apt-get install libnss-ldap; #此套件安裝過程會自動提問進行相關設置;
ls -l /etc/*nss*; #看看同nss_ldap相關的配置文件(適用于Debian系統);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-rw-r--r-- 1 root root /etc/libnss-ldap.conf #這就是nss_ldap的配置文件了;
-rw------- 1 root root /etc/libnss-ldap.secret #這是登錄LDAP服務器的明文密碼;
-rw-r--r-- 1 root root /etc/nsswitch.conf #此文件需修改(參考后面步驟);
-rw-r--r-- 1 root root /etc/nsswitch.ldap #一個nsswitch.conf文件的樣本;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
vim /etc/libnss-ldap.conf; #如下安裝過程自動配置的項目(適用于Debian系統);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
base dc=hung,dc=mooo,dc=com
uri ldap://10.10.0.1/
ldap_version 3
rootbinddn cn=admin,dc=hung,dc=mooo,dc=com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
【在RedHat系統中使用套件管理工具來安裝nss_ldap套件】
在RedHat系統中,通常默認應該已經安裝好了nss_ldap套件, 如果您的系統還未安裝,也可以
使用 yum 或相應的 rpm 命令來安裝此套件: yum install nss_ldap;
同Debian系統不同的是, 在RedHat系統中所有同認證相關的配置,都可以通過一個管理工具來
集中處理, 這個管理工具就是 authconfig(或authconfig-tui), 它是一個可以使用文本菜單
來進行各種配置操作的工具程式. 當然,為了學習目的, 這里還是介紹一下手工修改所需調整
的幾個配置文件(也可參考類似的NIS設置相關部分). 例如:
vim /etc/sysconfig/authconfig; #(此文件只適用于RedHat系統);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
USELDAP=yes
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cat /etc/ldap.conf | grep -v ^# | grep .; #RedHat的nss_ldap調用的是此文檔;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
base dc=hung,dc=mooo,dc=com
timelimit 120
bind_timelimit 120
idle_timelimit 3600
nss_initgroups_ignoreusers root,ldap,named,avahi,haldaemon
uri ldap://10.10.0.1/
ssl no
tls_cacertdir /etc/openldap/cacerts
pam_password md5
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
請注意: nss_ldap所使用的配置文件的路徑是/etc/ldap.conf, 這同LDAP客戶端的配置文件
/etc/openldap/ldap.conf路徑是不相同的(未知兩者是否可共用).
authconfig --test | grep nss_ldap -A 3; #看看系統的授權情況;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
nss_ldap is enabled
LDAP+TLS is disabled
LDAP server = "ldap://10.10.0.1/"
LDAP base DN = "dc=hung,dc=mooo,dc=com"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
【使用Tarball資源來安裝nss_ldap套件】
也可以手工安裝nss_ldap套件(但必須自行設置相關配置文件及其參數):
wget http://www.padl.com/download/nss_ldap.tgz;
tar zxvf nss_ldap.tgz;
cd nss_ldap-259/;
./configure;
make;
make check;
make install;
(?采用Tarball資源安裝不適用于Debian系統?沒有相關配置文件?還是有bug?);
[2] 調整nsswitch.conf配置文件
在Linux系統中,可以通過NSS(/etc/nsswitch.conf)來設置各種應用的多種查詢來源, 因此也
可以通過NSS來設置您的系統查詢LDAP服務器的用戶資料,只需要在nsswitch.conf配置文件中
修改(或添加)查詢順序, 指定查詢時使用LDAP數據庫即可.
vim /etc/nsswitch.conf; #調整passw,shadow和dgroup的查詢順序;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
passwd: files ldap #在后面加上ldap表示在第二順序啟用LDAP來驗證;
group: files ldap #在后面加上ldap表示在第二順序啟用LDAP來驗證;
shadow: files ldap #在后面加上ldap表示在第二順序啟用LDAP來驗證;
hosts: files dns
networks: files
protocols: db files
services: db files
ethers: db files
rpc: db files
netgroup: nis
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
請注意: 上述這個例子是針對我的Debian系統的, 在您的系統中可能內容不盡相同, 但基本上
應該是類似的,都是調整上述三個參數即可(例如原本的搜尋順序可能不止files一個).
[3] 現在可以測試看看能否從LDAP服務器中查詢用戶帳號:
getent passwd; #正常情況下此命令應返回本機和LDAP服務器的大量帳號資料;
id testing4; #顯示只在LDAP服務器中才具有的帳號,可確認LDAP服務器能否提供用戶資料;
----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
(8) 在LDAP客戶端配置PAM來使用LDAP服務器提供認證服務
----------------------------------------------------------------------------------
【在Debian系統安裝libpam-ldap】
在Debian系統中使用套件管理工具來安裝libpam-ldap套件:
apt-get install libpam-ldap; #此套件安裝過程會自動提問進行相關設置;
ll /lib/security/pam_ldap.so; #安裝完成之后,就會添加這個庫模塊;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-rw-r--r-- 1 root root 37840 Mar 10 2007 /lib/security/pam_ldap.so
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cat /etc/pam_ldap.conf; #如下是按照時自動設置的參數;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
base dc=hung,dc=mooo,dc=com
uri ldap://10.10.0.1/
ldap_version 3
binddn cn=admin,dc=hung,dc=mooo,dc=com
bindpw 721115
pam_password crypt
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ll /etc/pam.d; #這是所有啟用了PAM認證的程式的相關設定;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-rw-r--r-- 1 root root 182 Jan 3 2006 atd
-rw-r--r-- 1 root root 384 Feb 27 2007 chfn
-rw-r--r-- 1 root root 581 Feb 27 2007 chsh
-rw-r--r-- 1 root root 392 Oct 4 06:23 common-account
-rw-r--r-- 1 root root 436 Oct 4 06:23 common-auth
-rw-r--r-- 1 root root 1097 Oct 4 06:23 common-password
-rw-r--r-- 1 root root 372 Oct 4 06:23 common-session
-rw-r--r-- 1 root root 289 Oct 14 2005 cron
-rw-r--r-- 1 root root 2843 Feb 27 2007 login
-rw-r--r-- 1 root root 38 Mar 8 2007 newrole
-rw-r--r-- 1 root root 520 Sep 1 2003 other
-rw-r--r-- 1 root root 92 Feb 27 2007 passwd
-rw-r--r-- 1 root root 38 Mar 8 2007 run_init
-rw-r--r-- 1 root root 69 May 30 17:53 samba
-rw-r--r-- 1 root root 1272 Mar 6 2007 ssh
-rw-r--r-- 1 root root 2305 Feb 27 2007 su
联系客服