歡迎您光臨本站 註冊首頁

samba+ldap認證問題

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

samba+ldap認證問題

samba 3.0 使用 LDAP 目錄認證
一般的 samba server 密碼是存在 /etc/samba/smbpasswd 中,它是一般的文字檔,對於較少是用者的 samba server 並不會有太大的問題,但是當使用者眾多時就會有以下的問題產生
1.查詢是循序進行,所以效能將會是瓶頸.
2.每一台 samba server 必須自己維護 smbpasswd 檔,當有多台 samba server 帳號的同步就是問題了.
3.smbpasswd 檔的格式限制了每個使用者可以維護的屬性.
這時就可以使用 LDAP 目錄來做身份驗證來解決以上的問題
Step0:需求1.openldap (RedHat 光碟中 openldap.rpm 可找到)
2.samba3.x (可到 http://www.samba.org 網站下載)
note: samba 2.x 預設的版本並不支援 LDAP 目錄的認證,需要重新編輯過才能使用
Setp1: 安裝
I.samba 3.x 安裝之前先移除 samba 2.x 的版本
#rpm -e samba-swat
#rpm -e samba-client
#rpm -e redhat-config-samba
#rpm -e samba
#rpm -e samba-common
#rpm -ivh samba-3.....i386.rpm
II.安裝 OpenLDAP
在 RedHat 第三片光碟片中的目錄 /mnt/cdrom/ReaHat/RPMS/可以找到所需的程式
#rpm -ivh openldap.....rpm
#rpm -ivh openldap-clients.....rpm
#rpm -ivh openldap-servers.....rpm
Step2: OpenLDAP 的設定
#vi /etc/openldap/slapd.conf
----------------------------------------------------------------------------------------------
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/nis.schema
include /etc/openldap/schema/samba.schema
..................略.................................
database ldbm
suffix "dc=example,dc=com"
rootdn "cn=Manager,dc=example,dc=com"
rootpw {SSHA}83DJ4KVwqlk1uh9k2uDb8+NT1U4RgkEs
..................略.................................
----------------------------------------------------------------------------------------------
加入 include /etc/openldap/schema/samba.schema 這一行,以支援 samba 使用 LDAP 的認證
note: samba.schema 檔案包在 samba.xxxx.rpm 中,安裝後存放在 /usr/share/doc/samba-3.0.0/examples/LDAP/ 目錄下.所以要手動複製檔案至 /etc/openldap/schema/ 目錄下.
#cp /usr/share/doc/samba-3.0.0/examples/LDAP/samba.schema /etc/openldap/schema/
上述以 example.com 為範例 suffix "dc=example,dc=com"
管理者為 Manager rootdn "cn=Manager,dc=example,dc=com"
使用管理者密碼 rootpw {SSHA}83DJ4KVwqlk1uh9k2uDb8+NT1U4RgkEs
管理者密碼的產生
#slappasswd
New password
Re-enter new password
{SSHA}83DJ4KVwqlk1uh9k2uDb8+NT1U4RgkEs
接下來再拷到 /etc/openldap/sldap.conf 的 rootpw 即可(怎麼拷,可以用滑鼠的左右建來做)
重新啟動 openldap
#service ldap restart
Step3:新增 LDAP 的分錄檔
I. 現在新增第一筆 BDN.ldif (Base Distinguish Name)資料至 openldap
#vi BDN.ldif
-------------------------------
dn:dc=example,dc=com
objectclass:top
-------------------------------

執行 ldapadd 將資料加入 OpenLDAP 中
# ldapadd -x -D "cn=Manager,dc=example,dc=com" -W -f BDN.ldif
Enter LDAP Password:
adding new entry "dc=example,dc=com"
這樣就成功加入一筆資料
II.新增使用者資料至 openldap
OpenLDAP 有提供工具將 /etc/passwd 的使用者,轉換成 LDAP 的使用者
工具存放在 /usr/share/openldap/migeation 中
首先編輯 /usr/share/openldap/migeation/migrate_common.ph 檔並
# vi /usr/share/openldap/migeation/migrate_common.ph
------------------------------------------------------------------------------------
..................略.................................
#DEFAULT_BASE = "dc=example,dc=com";
-------------------------------------------------------------------------------------
修改 #DEFAULT_BASE = "dc=example,dc=com"; 成系統欲設定的組織領域名稱
在轉換之前 user1 必須先存在 /etc/passwd 中,所以先新增 user1 這個使用者
#adduser user
#passwd user1
Changing password for user1 user1
New password:
Retype new password:
passwd: all authentication tokens updated successfully
我們只需要轉換 user1 這個使用者所以我必須先精簡 /etc/passwd 檔案成只有 user1 這個使用者
#cp /etc/passwd /etc/openldap/user1
#vi /etc/openldap/user1
-----------------------------------------------------------
user1:x:500:500::/home/user1:/bin/bash
-----------------------------------------------------------
接下來開始轉換
# /usr/share/openldap/migeation//migrate_passwd.pl /etc/openldap/user1 > user1.ldif
轉出來的 LDIF 檔內容就如同下面所用的範例,但我只是做簡單設定所以直接將使用者放置在根目錄下,而不是用 ou=People 來存放(所以要移除 ou=People)
-------------------------------------------------------------------------------------
dn: uid=user1,dc=example,dc=com
uid: user1
cn: user1
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword: {crypt}$1$YKgbc0rJ$Db9hUhK.eYQdmi6NFyz8U.
shadowLastChange: 12374
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 500
gidNumber: 500
homeDirectory: /home/user1
-------------------------------------------------------------------------------------

執行 ldapadd 將資料加入 OpenLDAP 中
#ldapadd -x -D "cn=Manager,dc=example,dc=com" -W -f user1.ldif
Enter LDAP Password:
adding new entry "uid=user1,dc=example,dc=com"
這樣就成功加入一筆資料
來搜尋一下結果吧
#ldapsearch -x -b 'ou=People,dc=example,dc=com'
--------------------------------------------------------------------------
version: 2
#
# filter: (objectclass=*)
# requesting: ALL
#
# People, example, com
dn: ou=People,dc=example,dc=com
objectClass: organizationalUnit
..................略........................
--------------------------------------------------------------------------
可以看到 'uid=user1,dc=example,dc=com' 成功加入,但這樣的資料還無法給 samba 來使用,最後我會再將 samba 所需的補上去.
Step4: samba 的設定
#vi /etc/samba/smb.conf
------------------------------------------------------------------------------
workgroup = EXAMPLE
netbios name =sun01
ldap admin dn = "cn=Manager,dc=example,dc=com"
passdb backend = ldapsam:ldap://192.0.0.1, guest
ldap ssl = off
ldap suffix = "dc=example,dc=com"
security = user
encrypt passwords = yes
------------------------------------------------------------------------------
說明
workgroup = EXAMPLE #所在的網域名稱,也是 OpenLDAP 之前設定的
netbios name =sun01 #netbios name 也就是 windows 的電腦名稱
ldap admin dn = "cn=Manager,dc=example,dc=com" #OpenLDAP 之前設定的管理者
passdb backend = ldapsam:ldap://192.0.0.1, guest #指定身份驗證交給 ldap server 來處理,其中的 IP 就是你的 OpenLDAP server 的 IP
ldap ssl = off #指定資料在網路傳送是否經由 ssl 加密,可用選項為 off:不使用 1.on(default):使用 2.ssl 加密 3.start tls:使用 tls(相似於 ssl) 加密
ldap suffix = "dc=example,dc=com" # samba 會從此資料路徑開始找起
security = user # 密碼驗證指定為 user
encrypt passwords = yes #密碼的傳送要先加密
重新啟動 samba server
#service smb restart
Restarting SMB services: Shutting down SMB services : [ OK ]
Starting down SMB services:
samba 要與 openldap 溝通前,samba 要先將 openldap 的密碼存在 /etc/samba/secrets.tdb,密碼就是剛剛設定 openldap 時要一樣
#smbpasswd -w secret
setting stored password for "cn=Manager,dc=example,dc=com" in secrets.tdb
最後我們還要修改 openldap 使用者的資料,才能給 samba 使用
step5: LDAP 加入 sambaAccount使用 smbpasswd 加入 sambaAccount 至 openldap 使用者
#smbpasswd -a user1
New SMB password:
Retype new SMB password:
Added user user1
來搜尋一下結果吧
#ldapsearch -x -b "uid=user1,dc=example,dc=com"
----------------------------------------------------------------------------------------------
dn: uid=user1,dc=example,dc=com
..................略........................
sambaSID: S-1-5-21-710610727-3552547972-1245264387-2000
sambaPrimaryGroupSID: S-1-5-21-710610727-3552547972-1245264387-2001
sambaPwdCanChange: 1069184314
sambaPwdMustChange: 2147483647
sambaLMPassword: FC26CDB2863917C1AAD3B435B51404EE
sambaNTPassword: 00B2C85DDFBD8CC81602D6FC7340EB0B
sambaPwdLastSet: 1069184314
sambaAcctFlags:
----------------------------------------------------------------------------------------------
可以看到很多以 samba 開頭的資料這些都是 openLDAP 要驗證 samba 使用者所需的資料
sambaSID: The security identifier(SID) of the user.The Windows equivalent of UNIX UIDs.
sambaPrimaryGroupSID: The security Identifier(SID) of the primary group of the user
sambaPwdCanChange: Specifies the time (UNIX time format) from which on the user is allowed to chamge his password. If attribute is not set,the user will be free to change his password whenever the wants.
sambaPwdMustChange: Specifies the time (UNIX time format) since when the user is forced to change his password. If this value is set to "0", the user will have to change his password at first login. If this attribute is not set , then the password will never expire.
sambaLMPassword: the LANMAN password 16-byte hash stored as a character represemtation of a hexadecimal
sambaNTPassword: the LANMAN password 16-byte hash stored as a character represemtation of a hexadecimal
sambaPwdLastSet: The integer time in seconds since 1970 when the lmPassword and ntPassword attributes were last set
sambaAcctFlags: string of 11 characters surrounded by square brackets [] representing account flags such as U(user),W(workatation),X(no password expiration),I(Domain trust account),H(Home dir required),S(Server trust account), and D(Disabled)
現在來試一試是否可以使用 LDAP 做為 samba 的驗證
#smbclient -L sun01 -U user1
Password:
Sharename Type Comment
--------- ---- -------
IPC$ IPC IPC Service (Samba Server)
ADMIN$ IPC IPC Service (Samba Server)
user1 Disk Home Directories
Server Comment
--------- -------
Workgroup Master
--------- -------
成功了
--------------------------
我的系統是:CentOS4.4,Samba和Openldap是系統自己帶的!
我按以上配置后執行至:#smbpasswd -a user1時報錯:
「failed to bind to server with dn= cn=Manager,dc=my-domian,dc=com Error: Invalid credentials」

"Connection to LDAP server failed for the 1 try"
"Connection to LDAP server failed for the 3 try"
.
.
.
不知道是怎麼回事?請高手指教!不勝感激!
《解決方案》

If using LDAP as backend db , smbpasswd need smbldap-tools to access ldap

so,may you need modify your smb.conf like below


passdb backend = ldapsam:ldap://127.0.0.1/
ldap admin dn = cn=Manager,dc=easy,dc=com (設置您的管理DN)
ldap suffix = dc=easy,dc=com (設置samba域搜索後綴)
ldap group suffix = ou=Groups (設置samba組搜索後綴)
ldap user suffix = ou=Users (設置samba用戶搜索後綴)
ldap machine suffix = ou=Computers (設置samba計算機搜索後綴)
ldap idmap suffix = ou=Users (如果samba作為PDC可以刪除)
dap ssl = off (設置ldap ssl為關閉)
ldap delete dn = Yes
add user script = /sbin/smbldap-useradd -m "%u"
add machine script = /sbin/smbldap-useradd -t 0 -w "%u"
add group script = /sbin/smbldap-groupadd -p "%g"
add user to group script = /sbin/smbldap-groupmod -m "%u" "%g"
delete user from group script = /sbin/smbldap-groupmod -x "%u" "%g"
set primary group script = /sbin/smbldap-usermod -g '%g' '%u'

from http://blog.chinaunix.net/u/12502/showart_290730.html

sorry ,no chinese input now

[火星人 ] samba+ldap認證問題已經有818次圍觀

http://coctec.com/docs/service/show-post-37671.html