Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 加入 Windows AD 域完整實施:Samba、Winbind、Kerberos 與 Oddjob 配置

編輯:Linux 教學

架構概覽

Linux 透過 Samba (Winbind) 與 AD 域控制器通訊,Kerberos 提供認證票據,Oddjob (mkhomedir) 自動建立家目錄,實現帳號密碼統一管理。

前置條件

  • DNS 正確解析域控制器 FQDN
  • 時間同步(NTP),誤差 < 5 分鐘
  • 域管理員帳號(具備加入電腦權限)

步驟 1:安裝套件

# RHEL/CentOS 7/8
yum -y install samba samba-client samba-common samba-winbind samba-winbind-clients \
  krb5-workstation krb5-libs pam_krb5 oddjob-mkhomedir

步驟 2:啟動服務

systemctl enable --now smb winbind oddjobd
# 驗證端口
netstat -tulnp | grep -E 'smb|winbind'
# 139, 445 (smb) ; 445 (winbind)

步驟 3:網路與 DNS 配置

# /etc/resolv.conf
search vinda.cn
nameserver 192.168.10.1   # AD DNS 伺服器

# /etc/hosts 確保本機 FQDN 解析
192.168.10.50  linux01.vinda.cn  linux01

在 AD DNS 新增 A 記錄:linux01.vinda.cn → 192.168.10.50

步驟 4:Kerberos 客戶端配置

# /etc/krb5.conf
[libdefaults]
  default_realm = VINDA.CN
  dns_lookup_realm = true
  dns_lookup_kdc = true
  ticket_lifetime = 24h
  renew_lifetime = 7d
  forwardable = true

[realms]
  VINDA.CN = {
    kdc = dc01.vinda.cn
    admin_server = dc01.vinda.cn
  }

[domain_realm]
  .vinda.cn = VINDA.CN
  vinda.cn = VINDA.CN
# 測試取得票據
kinit administrator@VINDA.CN
klist

步驟 5:Samba / Winbind 配置

# /etc/samba/smb.conf
[global]
  workgroup = VINDA
  realm = VINDA.CN
  security = ads
  dedicated keytab file = /etc/krb5.keytab
  kerberos method = secrets and keytab
  winbind use default domain = true
  winbind offline logon = false
  winbind nss info = rfc2307
  idmap config * : backend = tdb
  idmap config * : range = 10000-20000
  idmap config VINDA : backend = rid
  idmap config VINDA : range = 10000-20000
  template shell = /bin/bash
  template homedir = /home/%U

步驟 6:NSS / PAM 整合

# /etc/nsswitch.conf
passwd:     files winbind
group:      files winbind
shadow:     files winbind

# /etc/pam.d/system-auth 及 password-auth 確認含有
auth        sufficient    pam_winbind.so
account     sufficient    pam_winbind.so
password    sufficient    pam_winbind.so
session     required      pam_mkhomedir.so skel=/etc/skel umask=0022

步驟 7:加入域

net ads join -U administrator
# 輸入密碼
# 輸出:Joined 'LINUX01' to dns domain 'vinda.cn'

步驟 8:驗證

# 查看域用戶/群組
wbinfo -u
wbinfo -g

# 測試域帳號登入 (UPN 格式)
ssh test01@vinda.cn@linux01
# 或
su - test01@vinda.cn

常見問題排查

  • 時間不同步:ntpdate dc01.vinda.cn
  • DNS 未解析:檢查 /etc/resolv.conf、AD DNS 記錄
  • Kerberos 票據失效:kdestroy; kinit administrator
  • Winbind 緩存:net cache flush
  • SELinux 阻擋:setsebool -P allow_ypbind=1 authlogin_nsswitch_use_ldap=1
Copyright © Windows教程網 All Rights Reserved