如何讓Linux機(jī)器加入Windows的AD域
對于帳戶統(tǒng)一管理系統(tǒng)或軟件來說,在 Linux 下你可能知道 NIS、OpenLDAP、samba 或者是 RedHat、IBM 的產(chǎn)品,在 Windows 下當(dāng)然就是最出名的活動(dòng)目錄 (Active Directory)(AD)了,這里就來探討一下如何讓 Linux 的計(jì)算機(jī)加入 AD 域。
首先,先簡單介紹一下 AD 域。自 Windows 2000 以來,AD 一直是 Windows 的身份驗(yàn)證和目錄服務(wù),AD 基于 LDAP 實(shí)現(xiàn)其功能,其使用 DNS 進(jìn)行主機(jī)名的解析,使用 Kerberos V5 進(jìn)行用戶身份驗(yàn)證,使用 LDAP V3 進(jìn)行統(tǒng)一的帳戶管理。
目標(biāo):在 AD 域中,將 Linux 服務(wù)器加入 AD,以使 Domain Admins 用戶組成員可以登錄操作 Linux 服務(wù)器,不需要在 Linux 服務(wù)器中單***建帳戶。
環(huán)境:一臺(tái) Windows Server 2012 R2 操作系統(tǒng)的服務(wù)器,安裝有 AD 并作為域控制器(Domain Controller)(DC),同時(shí)也作為 DNS 服務(wù)器和時(shí)間服務(wù)器;一臺(tái) RedHat Enterprise Linux 6.x 的服務(wù)器,請自行配置好網(wǎng)絡(luò)及 YUM 源。有關(guān) AD 域服務(wù)器的搭建,由于比較簡單,請自行查閱資料完成,這里不再詳述。
這里以 Windows 服務(wù)器地址為 192.168.2.122,域名為 contoso.com,主機(jī)名為 ad.contoso.com;Linux 服務(wù)器地址為 192.168.2.150,主機(jī)名為 lemon20.contoso.com。
1、安裝所需軟件:
- # yum -y install samba samba-client samba-common samba-winbind samba-winbind-clients krb5-workstation ntpdate
2、設(shè)置服務(wù)自啟動(dòng)并啟動(dòng)服務(wù):
- # chkconfig smb on
- # chkconfig winbind on
- # service smb start
- # service winbind start
3、修改 /etc/hosts 文件,添加主機(jī)對應(yīng)記錄:
- 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
- ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
- 192.168.2.150 lemon20.contoso.com lemon20
4、設(shè)置 DNS 地址并與 AD 服務(wù)器同步時(shí)間:
- # echo "nameserver 192.168.2.122" >> /etc/resolv.conf
- # ntpdate ad.contoso.com
5、設(shè)置 Kerberos 票據(jù)(可選):
銷毀已經(jīng)存在的所有票據(jù):
- # kdestroy
查看當(dāng)前是否還存在票據(jù):
- # klist
- klist: No credentials cache found (ticket cache FILE:/tmp/krb5cc_0)
生成新的票據(jù),注意域名大寫。
- # kinit administrator@CONTOSO.COM
- # klist
- Ticket cache: FILE:/tmp/krb5cc_0
- Default principal: administrator@CONTOSO.COM
- Valid starting Expires Service principal
- 08/02/16 22:35:26 08/03/16 08:35:29 krbtgt/CONTOSO.COM@CONTOSO.COM
- renew until 08/09/16 22:35:26
6、以命令方式設(shè)置 samba 與 Kerberos,并加入 AD 域:
- #authconfig --enablewinbind --enablewins --enablewinbindauth --smbsecurity ads --smbworkgroup=CONTOSO --smbrealm CONTOSO.COM --smbservers=ad.contoso.com --enablekrb5 --krb5realm=CONTOSO.COM --krb5kdc=ad.contoso.com --krb5adminserver=ad.contoso.com --enablekrb5kdcdns --enablekrb5realmdns --enablewinbindoffline --winbindtemplateshell=/bin/bash --winbindjoin=administrator --update --enablelocauthorize --enablemkhomedir --enablewinbindusedefaultdomain
注意命令中的大小寫,此步驟也可以使用 authconfig-tui 完成。
7、增加 sudo 權(quán)限(可選):
- # visudo
加入下列設(shè)置:
- %MYDOMAIN\\domain\ admins ALL=(ALL) NOPASSWD: ALL
8、確認(rèn)是否正確加入 AD 域:
查看 AD 的相關(guān)信息
- # net ads info
查看 MYDOMAIN\USERID 的使用者帳戶
- # wbinfo -u
補(bǔ)充:
如果啟用 selinux 的話,需要安裝 oddjobmkhomedir 并啟動(dòng)其服務(wù),這樣才能確保系統(tǒng)對創(chuàng)建的家目錄設(shè)置合適的 SELinux 安全上下文。