查看完整版本: Linux用winbind與AD認證筆記

danny 2006-11-19 18:53

Linux用winbind與AD認證筆記

筆記參考來源~
施威銘 lunix與Windows異質平台整合
酷學園討論區

第一節、Linux採用AD認證
假設 區域網路中AD主機為 server.test.com.tw 、IP為192.168.0.86
(一).設定samba
[root@linux2 /]# vi /etc/samba/smb.comf
[global]

# workgroup = NT-Domain-Name or Workgroup-Name
workgroup = test ---指定網域名稱
realm = test.com.tw ---完整網域名稱
# server string is the equivalent of the NT Description field
netbios name = Data_Server ---Samba主機名稱
server string = Linux --- 主機描述
……………………………………………………………………………
…………………………………………………………………………………….
# Security mode. Most people will want user level security. See
# security_level.txt for details.
security = ads ---設定安全等級為AD ,表示由AD來做帳號認證
# Use password server option only with security = server
; password server = <NT-Server-Name>
password server = server.test.com.tw

# Password Level allows matching of _n_ characters of the password
# all combinations of upper and lower case.
; password level = 8
; username level = 8

# You may wish to use password encryption. Please read
# ENCRYPTION.txt, Win95.txt and WinNT.txt in the Samba documentation.
# Do not enable this option unless you have read those documents
encrypt passwords = yes ---採用編碼方式傳遞密碼
; smb passwd file = /etc/samba/smbpasswd


存檔離開
(二) 如果沒有DNS做轉址,那必須修改hosts檔,位置在 /etc/hosts
[root@linux2 /]# vi /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 linux2.test.com.tw linux2 localhost.localdomain localhost
192.168.0.86 server.test.com.tw test.com.tw

(三) 修改Kerberos 位置在 /etc/krb5.conf
[logging]
default = FILE:/var/log/krb5libs.log
kdc = FILE:/var/log/krb5kdc.log
admin_server = FILE:/var/log/kadmind.log

[libdefaults]
default_realm = SERVER.TEST.COM.TW ---改成AD主機
dns_lookup_realm = false
dns_lookup_kdc = false

[realms]
TEST.COM.TW = { ---改成網域
kdc = SERVER.TEST.COM.TW:88
admin_server = SERVER.TEST.COM.TW:749 ---AD主機名稱
default_domain = TEST.COM.TW ----網域名稱
}

[domain_realm]
.example.com = TEST.COM.TW
.example.com = TEST.COM.TW

(四) 修改 /var/kerberos/krb5kdc/kdc.conf (如果沒有此檔案,則代表未安裝krb5-server,請由光碟安裝)
[root@linux2 /]#vi /var/Kerberos/krb5kdc/kdc.conf
[kdcdefaults]
acl_file = /var/Kerberos/krb5kdc/kadm5.acl
dict_file = /usr/share/dict/word
admin_keytab = /var/Kerberos/krb5kdc/kadm5.keytab
v4_mode = nopreauth

[realms]
TEST.COM.TW = { ---網域名稱
Master_key_type = des-cdc-crc
Supported_enctypes = arcfour-hmac:normal arcfour-hma

(五)測試連線
[root@linux2 /]# kinit [email][email protected][/email]
如果正常則會跳回命令提示字元
網域名稱是大寫喔
AD主機與Linux主機兩台時間不得相差超過5分鐘
(六)將Samba主機加入網域
[root@linux2 /]# service smb restart
[root@linux2 /]# net ads join
當出現 Joined “Linux” to realm “test.com.tw” 則代表成功。

(七)Winbind運作
(1) 設定NSS設定檔 設定檔在 /etc/nsswitch.conf
[root@linux2 /]# vi /etc/nssswitch.conf
# Example:
#passwd: db files nisplus nis
#shadow: db files nisplus nis
#group: db files nisplus nis

passwd: files winbind &szlig;加入winbind
shadow: files
group: files winbind &szlig;加入 winbind

#hosts: db files nisplus nis dns
hosts: files dns

(八) 修改gid與uid的範圍(linux從AD抓取過來的帳號)
及目錄
[root@linux2 /]vi /etc/samba/smb.conf
idmap uid = 16777000-33550000
idmap gid = 16777000-33550000
template shell = /bin/bash
winbind use default domain = yes
template homedir = /home/winnt/%D/%U
重新啟動Samba
[root@linux2 /]# service smb restart
(九) 啟動winbind
[root@linux2 /]# chkconfig winbind on
[root@linux2 /]# service winbind start

(十) 測試取得AD帳號資訊
[root@linux2 /]# wbinfi –u

[root@linux2 /]# getent passwd
(十一) 設定本機uid與gid 發放範圍,以避免Linux帳號與AD帳號衝突
修改的檔案在 /etc/login.defs
[root@linux2 /]# vi /etc/login.defs
# Min/max values for automatic uid selection in useradd
#
UID_MIN 500
UID_MAX 9999 ---修改為9999
#
# Min/max values for automatic gid selection in groupadd
#
GID_MIN 500
GID_MAX 9999 ---修改為9999
#

(十二) 整合
(1) 我們必須建立AD帳號在Linux的虛擬目錄,由於AD帳號過多的狀況下我們一個個建立會浪費時間,所以我們可以利用指令稿來快速建立
在root 的目錄底下 我們新增一個檔案mknthome.awk
[root@linux2 ~]# vi mknthome.awk
內容如下
#!/bin/awk
BEGIN {
FS = “:”
uidmin = 16777000
uidmax = 33550000


}

{
if ($3 >= uidmin && $3 <= uidmax ) {
print “\nmake directory “ $6 “\nchown “ $3 “.” $4 “ “ S6
system ( “mkdir -p “ $6 “ ;chown “ $3 “.” $4 “ “ $6 )
}
}

(2) 開始建立家目錄了
[root@linux2 ~]# getent passwd | awk -f mknthome.awk
此時你會看到畫面自動幫你建立帳號了,如果沒有請檢查mknthome指令稿有沒有錯

(3)開始整合帳號
依照我們的需求來修改ssh smtp dovecot 等等檔案
目錄分別為目錄分別在 /etc/pam.d/sshd /etc/pam.d/smtp /etc/pam.d/dovecot
先修改 ssh
[root@linux2 /]# vi /etc/pam.d/sshd
#%PAM-1.0
auth sufficient pam_winbind.so ---加入這行
auth required pam_stack.so service=system-auth
auth required pam_nologin.so
account required pam_stack.so service=system-auth
account sufficient pam_winbind.so ---加入這行
password required pam_stack.so service=system-auth
session required pam_stack.so service=system-auth

修改 smtp
[root@linux2 /]# vi /etc/pam.d/smtp
#%PAM-1.0
auth sufficient pam_winbind.so ---加入這行
auth required pam_stack.so service=system-auth
account sufficient pam_winbind.so ---加入這行
account required pam_stack.so service=system-auth

修改 dovecot
[root@linux2 /]# vi /etc/pam.d/dovecot
#%PAM-1.0
auth sufficient pam_winbind.so ---加入這行
auth required pam_nologin.so
auth required pam_stack.so service=system-auth
account sufficient pam_winbind.so ---加入這行
account required pam_stack.so service=system-auth
session required pam_stack.so service=system-auth
頁: [1]
查看完整版本: Linux用winbind與AD認證筆記