samba、winbind、krb5-client、oddjob-mkhomedir。chronyd/ntpd 必須與 DC 時間差 < 5 分鐘。/etc/resolv.conf nameserver 設為 DC IP。[global]
workgroup = EXAMPLE # NetBIOS 域名 (短名)
realm = EXAMPLE.COM # Kerberos Realm (大寫)
security = ads # Active Directory 模式
dedicated keytab file = /etc/krb5.keytab
kerberos method = secrets and keytab
winbind use default domain = yes
winbind enum users = yes
winbind enum groups = yes
winbind nested groups = yes
winbind refresh tickets = yes
template shell = /bin/bash
template homedir = /home/%U
idmap config * : backend = tdb
idmap config * : range = 10000-20000
idmap config EXAMPLE : backend = rid
idmap config EXAMPLE : range = 1000000-2000000
# 可選:AD 站點優化
# socket options = TCP_NODELAY IPTOS_LOWDELAY
[libdefaults]
default_realm = EXAMPLE.COM
dns_lookup_realm = true
dns_lookup_kdc = true
ticket_lifetime = 24h
renew_lifetime = 7d
forwardable = true
[realms]
EXAMPLE.COM = {
kdc = dc1.example.com
kdc = dc2.example.com
admin_server = dc1.example.com
default_domain = example.com
}
[domain_realm]
.example.com = EXAMPLE.COM
example.com = EXAMPLE.COM
passwd: files winbind
group: files winbind
shadow: files winbind
hosts: files dns
auth sufficient pam_winbind.so use_first_pass krb5_auth krb5_ccache_type=FILE
auth required pam_deny.so
account sufficient pam_winbind.so
account required pam_permit.so
password sufficient pam_winbind.so use_authtok
password required pam_deny.so
session required pam_mkhomedir.so skel=/etc/skel umask=0077
session optional pam_winbind.so
# 1. 測試 Kerberos 認證
kinit administrator@EXAMPLE.COM
klist
# 2. 加入域 (Samba 4.13+ 推薦 net ads join)
net ads join -U administrator -D EXAMPLE.COM
# 輸入域管理員密碼,提示 "Joined 'EXAMPLE' domain" 即成功
# 3. 重啟服務
systemctl restart smb nmb winbind
systemctl enable --now smb nmb winbind oddjobd
# 4. 驗證
wbinfo -u | head # 列出域用戶
wbinfo -g | head # 列出域組
getent passwd administrator
id administrator@EXAMPLE.COM
net ads testjoin # 測試信任關係
| 現象 | 原因與解決 |
|---|---|
| NT_STATUS_UNSUCCESSFUL / KDC reply did not match expectations | 時間不同步 → chronyc makestep 強制同步;DNS 未指向 DC → 檢查 /etc/resolv.conf。 |
| winbindd 啟動失敗 / id 映射失敗 | idmap 配置衝突 → 確保 idmap config * : backend = tdb 且域專用 backend (rid/ad) 範圍不重疊。 |
| 無法解析域用戶組 | nsswitch.conf 未包含 winbind → 添加 passwd: files winbind group: files winbind。 |
| Kerberos 票據過期導致掛載失效 | 啟用 winbind refresh tickets = yes,確保 oddjobd 運行。 |
[data]
path = /srv/data
read only = no
browsable = yes
valid users = @"EXAMPLE\Domain Users"
force group = +"EXAMPLE\DataGroup"
create mask = 0660
directory mask = 2770
vfs objects = acl_xattr
map acl inherit = yes
關鍵五件套:時間同步 + DNS 指向 DC + kerberos 認證 (kinit) + net ads join + winbind/nsswitch/pam 串聯。配置完成後,Linux 即成為域信任成員,支持域用戶登錄、文件權限映射、Kerberos 單點登錄,實現異構環境無縫融合。