為了在Windows主機間達到資源共享的目的,微軟發展出 SMB(Server Message Block)通訊協定,利用其網路芳鄰共享檔案系統及印表機等資源;而Samba在Linux主機上實現SMB通訊協定的系統,達成Windows與 Linux主機的資源共享,再搭配 Winbind 模組解決 Samba 中統一登入問題。因為 Linux Server 愈來愈多,為了可以達到統一單一帳號來達到管理,因此; 接下來我們要利用 samba、winbind 來整合 AD 帳號,這樣我們就可以在 AD 管理帳號就可以了。
環境:
Windows Server 2003 AD Server: ADSERVER.WEI.COM (192.168.2.1)
Oracle Linux R6.5 for x86_64 (64 Bit) :cvs.wei.com (192.168.2.69)
一、Linux 相關套件安裝與設定
1) 在安裝 Linux 主機時,可以選取相關的套件
2) 檢查/驗證一下相關的套件是否有裝
[root@cvs ~]# rpm -qa | grep samba
samba-common-3.6.9-164.el6.x86_64
samba-client-3.6.9-164.el6.x86_64
samba4-libs-4.0.0-58.el6.rc4.x86_64
samba-winbind-3.6.9-164.el6.x86_64
samba-3.6.9-164.el6.x86_64
samba-winbind-clients-3.6.9-164.el6.x86_64
[root@cvs ~]# rpm -qa | grep winbind
samba-winbind-3.6.9-164.el6.x86_64
samba-winbind-clients-3.6.9-164.el6.x86_64
[root@cvs ~]# rpm -qa | grep krb5
krb5-workstation-1.10.3-10.el6_4.6.x86_64
krb5-server-1.10.3-10.el6_4.6.x86_64
pam_krb5-2.3.11-9.el6.x86_64
krb5-libs-1.10.3-10.el6_4.6.x86_64
3) 使用 UI 工具來作設定
設定好後 Apply,然後記得要在 Identity & Authentication 按下 Join Domain,在 AD 的 Computers 中應該可以看到此 Linux : cvs 主機
4) 啟動 Samba & Winbind Services
5) 最後使用 AD Domain User 來作登入測試,應該就可以成功了。
6) 若有目錄要給 AD Domain Users 群組可以使用, 可以用指令 # chown -R root:"WEI\Domain Users" /opt/cvs_root/ 來賦予.
Oracle Linux 在使用 samba、winbind 來整合 AD 帳號的 UI 畫面已經整合的非常好,/etc/samba/smb.conf & /etc/krb5.conf 都不需去多作編輯:只有 /var/kerberos/krb5kdc/kdc.conf 檔案內容中的 EXAMPLE.COM 要改成您的 AD 網域(如:WEI.COM),以及將 master_key_type 前的 # 去除即可。相關檔案如下:
| [root@cvs samba]# cat /etc/samba/smb.conf #======================= Global Settings ===================================== [global] #--authconfig--start-line-- # Generated by authconfig on 2014/01/15 15:41:06 # DO NOT EDIT THIS SECTION (delimited by --start-line--/--end-line--) # Any modification may be deleted or altered by authconfig in future workgroup = WEI password server = ADSERVER.WEI.COM realm = WEI.COM security = ads idmap config * : range = 16777216-33554431 template shell = /bin/bash winbind use default domain = false winbind offline logon = true #--authconfig--end-line-- |
| [root@cvs samba]# cat /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 = WEI.COM dns_lookup_realm = false dns_lookup_kdc = false ticket_lifetime = 24h renew_lifetime = 7d forwardable = true [realms] EXAMPLE.COM = { kdc = kerberos.example.com admin_server = kerberos.example.com } WEI.COM = { kdc = ADSERVER.WEI.COM } [domain_realm] .example.com = EXAMPLE.COM example.com = EXAMPLE.COM |
|
# vi /var/kerberos/krb5kdc/kdc.conf |
二、Samba 3.x 伺服器設定說明
設定Samba最基礎的項目就是指定工作群組名稱(workgroup)及網域名稱,編輯 Samba設定檔smb.conf,以下設定都在該檔案內[global]標籤下同一段落完成。
/etc/samba/smb.conf
| workgroup = WEI realm = WEI.COM |
避免分享資源時出現亂碼,分別設定Windows、Linux的字集。
| display charset = Big5 dos charset = CP950 |
使用AD網域認證必須修改Samba的安全層級,並指定認證主機及增加Windows網路相關設定。
| security = ads password server = ADSERVER.WEI.COM wins server = ADSERVER.WEI.COM encrypt passwords = yes |
Linux預設的使用者家目錄為/home/使用者名稱,針對AD網域使用者 必須另行設定其家目錄位置,主要參數為:%D代表網域名稱、%U代表使用者名稱。以下設定目的為讓網域使用者的家目錄集中在/home/網域名稱/目錄下 並以使用者帳號命名,同時讓使用者帳號自動套用網域名稱及不允許使用者離線登入。
| template homedir = /home/%D/%U winbind use default domain = false winbind offline logon = true |
設定AD網域使用者帳號對應到Linux使用者帳號及群組的範圍。
| idmap config * : range = 16777216-33554431 |
預設Winbind快取時間為300秒,使用指令# getent passwd或# getent group時,會將NT/AD網域的使用者與群組一併列出。當使用者、群組數量太多,Winbind會無法正常傳回資料,開啟此功能可以避免這個狀況。
| winbind enum users = yes winbind enum groups = yes winbind cache time = 300 |
若允許AD網域使用者以終端機方式登入系統,可指定AD帳號的Shell。
| template shell = /bin/bash |
視需要開啟對NT ACLs(Access Control List) 的支援。
| nt acl support = yes |
三、整合Windows AD網域帳號資訊說明
當系統查詢使用者帳號與群組時,預設由檔案尋找(/etc/passwd、/etc/group),為了使其搜尋不到相關資訊時,轉而使用Winbind向AD網域查詢,必須設定認證來源和順序。
/etc/nsswitch.conf
| passwd: files winbind shadow: files winbind group: files winbind |
設定本機 UID 與 GID 發放範圍,避免 AD 帳號與 Linux 本機帳號衝突,限制本機分配給新使用者的uid、gid不要超過9999。
/etc/login.defs
| UID_MIN 500 UID_MAX 9999 GID_MIN 500 GID_MAX 9999 CREATE_HOME yes |
四、Linux Server加入AD網域
在將主機加入網域之前,需先確認AD主機及Linux主機時間不得相差超過5分鐘,建議設定同一網路校時服務(Network Time Protocol),並設定DNS或host使Linux主機得知AD網域伺服器的IP位址,任修改其中一種能查詢到網域即可。
/etc/resolv.conf
| Nameserver 192.168.2.1 |
/etc/hosts
| 192.168.2.1 adserver.wei.com |
由於Windows Server 2003的AD是採用Kerberos的認證機制,因此必須設定Kerberos相關設定檔以便和AD溝通。
/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 = WEI.COM dns_lookup_realm = false dns_lookup_kdc = false ticket_lifetime = 24h renew_lifetime = 7d forwardable = true WEI.COM = { kdc = ADSERVER.WEI.COM } |
/var/kerberos/krb5kdc/kdc.conf
| [kdcdefaults] kdc_ports = 88 kdc_tcp_ports = 88 [realms] WEI.COM = { master_key_type = aes256-cts acl_file = /var/kerberos/krb5kdc/kadm5.acl dict_file = /usr/share/dict/words admin_keytab = /var/kerberos/krb5kdc/kadm5.keytab supported_enctypes = aes256-cts:normal aes128-cts:normal des3-hmac-sha1:normal arcfour-hmac:normal des-hmac-sha1:normal des-cbc-md5:normal des-cbc-crc:normal } |
完成以上設定後重新啟動Samba及Winbind並加入設開機啟動。
| # service smb restart # service winbind restart # chkconfig smb on # chkconfig winbind on |
文字模式下指令加入wei.com 網域,aduser為AD網域之使用者,只需一般權限即可。
| # net ads join -U aduser aduser's password: |
設定與AD伺服器溝通時的使用者(經測試是不需要作此動作的)。
| # wbinfo --set-auth-user=aduser Password: |
一般Windows使用者在加入網域後存取不會有太大的問題,但Linux Clients使用者需要向Kerberos要求憑證(ticket)。可下指定測試取得Kerberos核發的憑證,取得後使用者不需要再輸入帳號密碼 存取資源,注意網域名稱要大寫,若密碼正確會跳回命令提示字元。
| # kinit 網域帳號@WEI.COM |
取得Kerberos核發的憑證後,可以看Kerberos核發的Kicket狀態。
| # klist |
測試讀取AD帳號資訊和取得系統帳號資訊。
| # wbinfo -u | -g 取得網域帳號 | 群組 # getent passwd |
參考文件:
http://michaeljoking.myip.org/modules/tad_book3/page.php?tbdsn=18
