以下資料來源參考自:
(1) http://ssorc.tw/?p=198
(2) http://blog.yam.com/keynes0918/article/31351174

 

環境:
(1) Windows AD Server:
                                   Homename:AD.COM
                                   IP Address:10.100.99.99
(2) CentOS 6.2 x64:
                                   Homename:HH-AABBCCSS
                                   IP Address:10.100.1.1 (以下設定並未用到)

(3) 需要一組用來驗證AD Server的一般使用者帳號(A12345)/密碼(以下範例使用的非管理者administrator帳號/密碼,而是一般使用者)。

 

 

一、CentOS 6.2 加入AD網域

Step 1) 安裝必要packages
$ yum install -y samba samba-common samba-winbind krb5-server krb5-workstation ntp

若是CentOS 5.5請安裝如下packages
$ yum install -y samba3x samba3x-common samba3x-winbind krb5-server krb5-workstation ntp

 

Step 2)
$ vim /etc/samba/smb.conf

------------------------------------------------------------------------------
[global]
#網域名稱
        workgroup = AD

#完整網域名稱
        realm = AD.COM

#Linux Samba主機描述
        server string = Samba Server Version %v

#Linux Samba主機名稱(Hostname)
        netbios name = HH-AABBCCSS
#安全等級為ads,帳號認證交由AD Server
        security = ads
#指定密碼AD Domain Server
        password server = AD.COM
#編碼方式傳遞密碼
        encrypt passwords = yes
#設定AD網域帳號的UID使用範圍
        idmap uid = 16777000-33550000
#設定AD網域帳號的GID使用範圍
        idmap gid = 16777000-33550000
#指定winbind是否在系統上建立網域使用者(Users)
        winbind enum users = yes
#指定winbind是否在系統上建立網域群組(Groups)
        winbind enum groups = yes
#網域與帳號之間分隔符號,此處設定「+」,表示「空白」
        winbind separator = +
#不顯示網域名稱
        winbind use default domain = yes
#設定登入後的Shell為何!
        template shell = /bin/bash
#設定使用者家目錄,%D指Domain,%U指User
        template homedir = /home/%D/%U


#額外補充:(只適用於單獨架設vsftpd整合AD)
#若不想讓使用者登入shell,可以設定以下參數:
#template shell = /sbin/nologin
#家目錄可以設定共同的目錄/var/ftp/pub,如下設定:
#template homedir = /var/ftp/pub
#用意在於當AD裡的使用者要登入FTP時,通通進入/var/ftp/pub
#至於之後新增目錄權限,可以使用$ id A12345來觀看所屬的Group ID
#並配合Linux filesystem ACL使用來設定檔案或目錄權限
#可以觀看我以下的文章設定:
#http://dreamtails.pixnet.net/blog/post/28140947
#若使用此額外補充設定方式,請不要做以下Step 19)與Step 20).

------------------------------------------------------------------------------

 

Step 3) $ vim /etc/hosts
------------------------------------------------------------------------------
10.100.99.99        AD.COM        AD
------------------------------------------------------------------------------ 

 

Step 4) $ vim /etc/krb5.conf
(若沒有此檔,表示沒有安裝krb5-server)
------------------------------------------------------------------------------
# AD是採kerberos認證機制,所以設定samba主機的kerberos與ad能溝通 ,注意大寫
[logging]

default = FILE:/var/log/krb5libs.log
kdc = FILE:/var/log/krb5kdc.log
admin_server = FILE:/var/log/kadmind.log

[libdefaults]
default_realm = AD.COM
dns_lookup_realm = false
dns_lookup_kdc = false
ticket_lifetime = 24h
renew_lifetime = 7d
forwardable = true

[realms]
AD.COM = {
kdc = AD.COM
admin_server = AD.COM
}

[domain_realm]
.example.com = AD.COM
example.com = AD.COM
------------------------------------------------------------------------------

 

Step 5) $ vim /var/kerberos/krb5kdc/kdc.conf

------------------------------------------------------------------------------
[kdcdefaults]
  kdc_ports = 88
  kdc_tcp_ports = 88

[realms]
  AD.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
  }
------------------------------------------------------------------------------

 

Step 6) 與AD Server作校時

$ ntpdate AD.COM

 

Step 7) 測試連線
$ kinit A12345@AD.COM
(注意大寫),輸入密碼無誤後,跳回提示字元

[Q1:] kinit(v5) : cannot find KDC for requested realm while getting initial credentials
[A1:] 網域名稱沒有大寫

[Q2:] kinit(v5) : clock skew too great while getting initial credentials
[A2:] samba與windows2003/2008系統時間相差不可超過5分鐘

[Q3:] kinit(v5) : preauthentication failed while getting initial credentials
[A3:] 密碼不對

 

 

Step 8) $ service smb restart

 

Step 9) $ net ads join -U A12345

加入網域,出現成功訊息為Joined 'HH-AABBCCSS' to realm 'AD.COM',
此時可在windows 2003/2008 Server上的AD使用者及電腦上的computers看到HH-AABBCCSS的名稱


 

二、讓Linux認證Windows AD網域帳號

Step 10) 檢查nss library
$ ldconfig -v | grep winbind 
顯示 libnss_winbind.so.2 -> libnss_winbind.so.2 

 

Step 11) $ vim /etc/nsswitch.conf

------------------------------------------------------------------------------
passwd:    files    winbind
group:    files    winbind
------------------------------------------------------------------------------ 

 

Step 12) $ service winbind restart

 

Step 13) 取得AD帳號
$ wbinfo -u 

 

Step 14) 取得本機與AD的帳號
$ getent passwd 

 

Step 15) 取得AD Server資訊
$ net ads info 

 

Step 16) 取得AD使用者(帳號)資訊
$ net ads status -U A12345 

 

Step 17) 解決本機(Linux Samba)與winbind分配給AD的UID與GID可能相衝的問題,把本機(Linux Samba)的UID與GID限制在9999之內。

$ vim /etc/login.defs
------------------------------------------------------------------------------
UID_MAX    16776999
GID_MAX    16776999
------------------------------------------------------------------------------ 

 

三、Linux中各種服務的帳號整合

Step 18) 確定winbind library
$ locate /pam_ | egrep '.so$'| grep 'winbind' 
------------------------------------------------------------------------------
/lib64/security/pam_winbind.so
------------------------------------------------------------------------------ 

 

Step 19) 建立主機(Linux Samba)使用者家目錄scripts:用來存取AD帳號時,可以找到自己所擁有的家目錄。
$ vim mkADhome.awk

------------------------------------------------------------------------------
#!/bin/awk
BEGIN {
FS=":"
uidmin=16777000
uidmax=33550000
}

{
        if ( $3 >= uidmin && $3 <= uidmax ) {
              print " make directory " $6 " chown " $3 "." $4 " " $6
              system( "mkdir -p " $6 ";chown " $3 "." $4 " " $6 )
        }
}
------------------------------------------------------------------------------

 

Step 20) 產生AD使用者的家目錄
$ getent passwd | awk -f mkADhome.awk

 

Step 21) 設定Linux本身系統登入使用AD驗證。
$ vim /etc/pam.d/system-auth

------------------------------------------------------------------------------
# 加入以下這四行
auth             sufficient     /lib64/security/pam_winbind.so
account        sufficient     /lib64/security/pam_winbind.so
password     sufficient     /lib64/security/pam_winbind.so
session         sufficient     /lib64/security/pam_winbind.so
------------------------------------------------------------------------------ 

 

Step 22) 設定vsftp登入使用AD驗證。
$ vim /etc/pam.d/vsftpd
------------------------------------------------------------------------------
# 加入以下這四行
auth             sufficient     /lib64/security/pam_winbind.so
account        sufficient     /lib64/security/pam_winbind.so
password     sufficient     /lib64/security/pam_winbind.so
session         sufficient     /lib64/security/pam_winbind.so
------------------------------------------------------------------------------ 

 

Step 23) 設定ssh登入使用AD驗證。
$ vim /etc/pam.d/sshd
------------------------------------------------------------------------------
# 加入以下這四行
auth             sufficient     /lib64/security/pam_winbind.so
account        sufficient     /lib64/security/pam_winbind.so
password     sufficient     /lib64/security/pam_winbind.so
session         sufficient     /lib64/security/pam_winbind.so
------------------------------------------------------------------------------ 

 

Step 24) 大功告成!

arrow
arrow
    全站熱搜

    dreamtails 發表在 痞客邦 留言(0) 人氣()