Active Directory 集成
来自 Wikipedia
本文档描述了如何使用 Samba 将 Arch Linux 系统集成到现有的 Windows 域网络中。
在继续之前,您必须拥有一个现有的 Active Directory 域,并且在域内拥有具有相应权限的用户,以便:查询用户和添加计算机帐户(域加入)。
本文档并非旨在成为 Active Directory 或 Samba 的完整指南。有关其他信息,请参阅资源部分。
简介
本文档解释了如何配置 Arch Linux 系统以参与 Active Directory 域。本文档是在全新安装上编写和测试的,并假定所有配置文件都处于未修改的、安装后的状态。在本文档的整个过程中,示例 Active Directory 域将使用以下配置
- NetBIOS 域名称: INTERNAL
- DNS 域名称: internal.domain.tld
- Kerberos 领域: INTERNAL.DOMAIN.TLD
- 第一台 DC: server1.internal.domain.tld,IP 地址为 192.168.1.1
- 第二台 DC: server2.internal.domain.tld,IP 地址为 192.168.1.2
在大多数小型网络中,DC(域控制器)也拥有 DNS 服务器角色。在大型网络中可能并非如此。通常,DC 也拥有 NTP 角色,但并非总是如此。请咨询您的网络管理员以验证 DNS 和 NTP 服务器的正确值。
所需软件
为了有效使用 Samba,您需要安装以下软件包: samba, smbclient, 和 ntp。( timedatectl 可用作 ntp 的替代方案。)
此外,虽然不是必需的,但以下软件包对于测试和故障排除将很有用: bind, krb5,如果您需要打印(无论您是想共享打印机,还是使用其他 Samba/Windows 主机上的打印机),还需要 cups。
服务初始配置
DNS 配置
Active Directory 完全依赖 DNS 进行名称解析。在 /etc/resolv.conf 文件中配置正确的 DNS 服务器和域搜索后缀至关重要。无论是通过 DHCP 还是静态配置,请确保这些值对您的域是正确的。对于示例域配置,以下内容是适用的(请务必将 192.168.1.1、192.168.1.2 和 internal.domain.tld 替换为您网络中的适当值)
/etc/resolv.conf
nameserver 192.168.1.1 nameserver 192.168.1.2 search internal.domain.tld
如果您选择安装 bind 软件包,您可以使用以下命令测试 DNS 配置(请务必将 server1 和 internal.domain.tld 替换为您网络中的适当值)
$ nslookup -type=SRV _kerberos._tcp.internal.domain.tld. $ nslookup -type=SRV _ldap._tcp.internal.domain.tld. $ nslookup server1.internal.domain.tld.
您应该会看到类似以下的输出(根据只有一个 DC 或超过两个 DC 的情况进行相应调整)
Server: 192.168.1.1 Address: 192.168.1.1#53 _kerberos._tcp.internal.domain.tld service = 0 100 88 server1.internal.domain.tld. _kerberos._tcp.internal.domain.tld service = 0 100 88 server2.internal.domain.tld. ... _ldap._tcp.internal.domain.tld service = 0 100 389 server1.internal.domain.tld. _ldap._tcp.internal.domain.tld service = 0 100 389 server2.internal.domain.tld. ... Name: server1.internal.domain.tld Address: 192.168.1.1
NTP 配置
在 Active Directory 域中,特别是对于 Kerberos 票据,网络上所有其他主机的时间同步至关重要。允许的误差不得超过五分钟。对于示例域配置,一个合适的 /etc/ntp.conf 文件应包含以下内容(请务必将 server1、server2 和 internal.domain.tld 替换为您网络中的适当值)
/etc/ntp.conf
# Use your domain's NTP servers server server1.internal.domain.tld server server2.internal.domain.tld # Restrictions restrict default kod limited nomodify nopeer noquery notrap restrict 127.0.0.1 restrict ::1 # Location of drift file driftfile /var/lib/ntp/ntpd.drift
启用并启动 ntpd.service 服务单元。
Kerberos 配置
Samba 文档建议进行最小化的 Kerberos 配置,仅在 [libdefaults] 部分包含足够的信息,以便通过 DNS 发现域的详细信息。不幸的是,这在实践中效果不佳。继续使用示例域配置,修改 /etc/krb5.conf 文件,使其包含以下内容(请务必将 INTERNAL、internal.domain.tld、SERVER1 和 INTERNAL.DOMAIN.TLD 的实例替换为您网络中的适当值)
/etc/krb5.conf
[libdefaults]
default_realm = INTERNAL.DOMAIN.TLD
dns_lookup_realm = false
dns_lookup_kdc = true
[realms]
INTERNAL.DOMAIN.TLD = {
kdc = SERVER1.INTERNAL.DOMAIN.TLD
default_domain = INTERNAL.DOMAIN.TLD
admin_server = SERVER1.INTERNAL.DOMAIN.TLD
}
INTERNAL = {
kdc = SERVER1.INTERNAL.DOMAIN.TLD
default_domain = INTERNAL.DOMAIN.TLD
admin_server = SERVER1.INTERNAL.DOMAIN.TLD
}
[domain_realm]
.internal.domain.tld = INTERNAL.DOMAIN.TLD
[appdefaults]
pam = {
ticket_lifetime = 1d
renew_lifetime = 1d
forwardable = true
proxiable = false
minimum_uid = 1
}
Samba 配置
基础 Samba 配置文件
Samba 的默认安装不附带示例 /etc/samba/smb.conf 文件。对于我们的示例域配置,请使用以下基础设置(请务必将 INTERNAL 和 INTERNAL.DOMAIN.TLD 的实例替换为您网络中的适当值)
/etc/samba/smb.conf
[global] workgroup = INTERNAL security = ADS realm = INTERNAL.DOMAIN.TLD winbind refresh tickets = Yes vfs objects = acl_xattr map acl inherit = Yes store dos attributes = Yes # Allow a single, unified keytab to store obtained Kerberos tickets dedicated keytab file = /etc/krb5.keytab kerberos method = secrets and keytab # Do not require that login usernames include the default domain winbind use default domain = yes
如果您不想共享在 cups 中配置的本地打印机,请将以下内容添加到 /etc/samba/smb.conf 文件的 [Global] 部分
/etc/samba/smb.conf
[Global] ... load printers = no printing = bsd printcap name = /dev/null disable spoolss = yes ...
其余配置取决于您的域是否支持 RFC2307 Unix/NFS 属性。如果不确定,请咨询您的域管理员。
为带有 RFC2307 扩展的域添加 idmap 配置
请确保以下值不与系统值重叠,并且所有用户至少具有 uidNubmer 属性,并且这些用户的 PrimaryGroup 具有 gid 属性。将以下内容附加到 /etc/samba/smb.conf 文件的 [Global] 部分(替换 INTERNAL 为 NetBIOS 域名称)
/etc/samba/smb.conf
[Global] ... # UID/GID mapping for local users idmap config * : backend = tdb idmap config * : range = 3000-7999 # UID/GID mapping for domain users idmap config INTERNAL : backend = ad idmap config INTERNAL : schema_mode = rfc2307 idmap config INTERNAL : range = 10000-999999 idmap config INTERNAL : unix_nss_info = yes # Template settings for users without ''unixHomeDir'' and ''loginShell'' attributes template shell = /bin/bash template homedir = /home/%U # Allow offline/cached credentials and ticket refresh winbind offline logon = yes winbind refresh tickets = yes ...
此外,如果 AD 中的用户帐户具有 gidNumber 属性,则可以使用它而不是 RID 作为用户的 Primary Group,方法是附加以下设置(同样在 [Global] 部分)
/etc/samba/smb.conf
[Global] ... idmap config INTERNAL:unix_primary_group = yes ...
为不带有 RFC2307 扩展的域添加 idmap 配置
如果您的管理员尚未扩展 AD 架构以包含 RFC2307 属性,请在 /etc/samba/smb.conf 文件的 [Global] 部分使用以下 idmap 配置(替换 INTERNAL 为 NetBIOS 域名称)
/etc/samba/smb.conf
[Global] ... # UID/GID mapping for local users idmap config * : backend = tdb idmap config * : range = 3000-7999 # UID/GID mapping for domain users idmap config INTERNAL : backend = rid idmap config INTERNAL : range = 10000-999999 # Template settings for users template shell = /bin/bash template homedir = /home/%U # Allow offline/cached credentials and ticket refresh winbind offline logon = yes winbind refresh tickets = yes ...
加入域
要加入 AD 域,只需发出以下命令(请务必将 Administrator 替换为具有加入 AD 域权限的用户)。
# net ads join -U Administrator
启动 individual Samba 服务
启用并启动 smb.service、nmb.service 和 winbind.service 服务。
配置 NSS
修改 /etc/nsswitch.conf 文件,允许 Samba 将名称映射到 uid 和 gid
/etc/nsswitch.conf
... passwd: files winbind mymachines systemd group: files winbind mymachines systemd ...
测试 NSS
通过列出系统已知的 AD 域用户和组来验证连通性
# wbinfo -u # wbinfo -g
您应该会看到 AD 用户列表,后跟 AD 组列表。
配置 PAM 认证
与其直接在 Linux-PAM 配置文件中配置选项,不如在 /etc/security/pam_winbind.conf 中设置 pam_winbind 模块的默认值
/etc/security/pam_winbind.conf
[Global] debug = no debug_state = no try_first_pass = yes krb5_auth = yes krb5_ccache_type = FILE:/run/user/%u/krb5cc cached_login = yes silent = no mkhomedir = yes
对于大多数服务,仅修改 /etc/pam.d/system-auth 文件就足够了。对于不包含此文件的程序的任何配置,也需要直接修改。创建 /etc/pam.d/system-auth 文件的备份,并使用以下配置
/etc/pam.d/system-auth
#%PAM-1.0 auth required pam_faillock.so preauth # Optionally use requisite above if you do not want to prompt for the password # on locked accounts. -auth [success=3 default=ignore] pam_systemd_home.so auth [success=2 default=ignore] pam_winbind.so auth [success=1 default=bad] pam_unix.so try_first_pass nullok auth [default=die] pam_faillock.so authfail auth optional pam_permit.so auth required pam_env.so auth required pam_faillock.so authsucc # If you drop the above call to pam_faillock.so the lock will be done also # on non-consecutive authentication failures. -account [success=2 default=ignore] pam_systemd_home.so account [success=1 default=ignore] pam_winbind.so account required pam_unix.so account optional pam_permit.so account required pam_time.so -password [success=2 default=ignore] pam_systemd_home.so password [success=1 default=ignore] pam_winbind.so password required pam_unix.so try_first_pass nullok shadow sha512 password optional pam_permit.so -session optional pam_systemd_home.so session required pam_mkhomedir.so skel=/etc/skel/ umask=0022 session required pam_limits.so session required pam_winbind.so session required pam_unix.so session optional pam_permit.so
如果您有其他不包含 /etc/pam.d/system-auth 文件的服务,请修改配置以镜像 pam_winbind.so 的所有 pam_unix.so 条目,并将所有 required 改为 sufficient。一个很好的例子是 su 配置。创建 /etc/pam.d/su 文件的备份,并用以下内容替换
/etc/pam.d/su
#%PAM-1.0 auth sufficient pam_rootok.so # Uncomment the following line to implicitly trust users in the "wheel" group. #auth required pam_wheel.so trust use_uid # Uncomment the following line to require a user to be in the "wheel" group. #auth required pam_wheel.so use_uid auth sufficient pam_winbind.so auth required pam_unix.so account sufficient pam_winbind.so account required pam_unix.so session sufficient pam_winbind.so session required pam_unix.so
上述 pam_winbind 配置将不使用 Kerberos 票据的默认位置(KRB5CCNAME),该位置为 /tmp/krb5cc_UID。相反,它会在登录时自动刷新 Kerberos 票据并将其存储到 /run/user/UID/krb5cc。将以下内容附加到您的 krb5.conf 中,让 Kerberos 知道您的新位置
/etc/krb5.conf
[libdefaults]
...
default_ccache_name = /run/user/%{uid}/krb5cc
...
要测试您的更改,请启动一个新的控制台或 ssh 会话(在彻底测试之前不要退出当前会话),然后尝试使用 AD 凭据登录。域名称是可选的,因为它已在 Winbind 配置中设置为“default realm”。请注意,对于 ssh,您需要修改 /etc/ssh/sshd_config 文件以允许 Kerberos 认证(见下文)。
运行 klist 以验证您是否收到了 Kerberos 票据。您应该会看到类似以下内容
$ klist
Ticket cache: FILE:/run/user/20000/krb5cc
Default principal: administrator@INTERNAL.DOMAIN.TLD
Valid starting Expires Service principal
12/25/2020 03:35:21 12/25/2020 13:35:21 krbtgt/INTERNAL.DOMAIN.TLD@INTERNAL.DOMAIN.TLD
renew until 12/26/2020 03:35:15
最后,在退出当前(有效)会话之前,您应该测试以 root 用户和本地非特权用户进行登录。
旧 Wiki 文章
Active Directory 是网络管理和安全性的中央位置。它负责验证和授权 Windows 域网络中的所有用户和计算机,为网络中的所有计算机分配和强制执行安全策略,并在网络计算机上安装或更新软件。例如,当用户登录到属于 Windows 域的计算机时,Active Directory 会验证其密码并指定他们是系统管理员还是普通用户。运行 Active Directory 的服务器计算机称为域控制器。
Active Directory 使用 Lightweight Directory Access Protocol (LDAP)版本 2 和 3,Microsoft 的 Kerberos 和 DNS 版本。
术语
如果您不熟悉 Active Directory,以下是一些有用的关键字。
- 域 : 用于分组计算机和帐户的名称。
- SID : 每个加入域的计算机都必须有一个唯一的 SID 或系统标识符。
- SMB : Server Message Block。
- NETBIOS: 网络命名协议,用作 DNS 的替代方案。主要是遗留的,但仍用于 Windows 网络。
- WINS: Windows 信息命名服务。用于将 Netbios 名称解析为 Windows 主机。
- Winbind: Windows 认证协议。
Active Directory 配置
本节针对 Windows Server 2012 R2 的默认配置。
GPO 考虑事项
数字签名在 Windows Server 中默认启用,并且必须在客户端和服务器级别启用。对于某些版本的 Samba,Linux 客户端可能会遇到连接到域和/或共享的问题。建议将以下参数添加到您的 smb.conf 文件
client signing = auto server signing = auto
如果无效,您可以禁用 AD 组策略中的数字签名通信(始终)。在您的 AD 组策略编辑器中,找到
在本地策略 > 安全策略 > Microsoft 网络服务器 > 数字签名通信(始终)下,激活定义此策略并使用禁用单选按钮。
如果您使用 Windows Server 2008 R2,您需要在GPO for Default Domain Controller Policy > Computer Setting > Policies > Windows Setting > Security Setting > Local Policies > Security Option > Microsoft network client: Digitally sign communications (always) 中进行修改。
请注意,禁用此 GPO 会影响域中所有成员的安全性。
Linux 主机配置
接下来的几个步骤将开始配置主机的过程。您需要 root 或 sudo 访问权限才能完成这些步骤。
安装
安装以下软件包
更新 DNS
Active Directory 严重依赖 DNS。您需要更新 /etc/resolv.conf 以使用一个或多个 Active Directory 域控制器
/etc/resolv.conf
nameserver <IP1> nameserver <IP2>
将
- /etc/resolv.conf 文件中的 DNS 条目 127.0.0.53 指的是 systemd-resolved 提供的本地 DNS 解析器。如果您使用 Network Manager 配置了 DNS 服务器,则此步骤是不必要的,并且如果您修改了建议的 resolv.conf,可能会导致问题。
- 如果您的机器双重启动 Windows 和 Linux,并且两个操作系统都将是同一域的成员,则 Linux 配置应使用不同的 DNS 主机名和 netbios 名称。
配置 NTP
阅读 System time#Time synchronization 以配置 NTP 服务。
在 NTP 服务器配置中,使用 AD 服务器的 IP 地址,因为它们通常运行 NTP 作为服务。或者,您可以使用其他已知的 NTP 服务器,只要 Active Directory 服务器同步到相同的层级。
确保该服务配置为在启动早期自动同步时间。
Kerberos
让我们假设您的 AD 名为 example.com。我们进一步假设您的 AD 由两个域控制器(主 DC 和辅助 DC)管理,它们分别命名为 PDC 和 BDC,pdc.example.com 和 bdc.example.com。在此示例中,它们的 IP 地址将是 192.168.1.2 和 192.168.1.3。注意您的语法;此处大写非常重要。
/etc/krb5.conf
[libdefaults]
default_realm = EXAMPLE.COM
clockskew = 300
ticket_lifetime = 1d
forwardable = true
proxiable = true
dns_lookup_realm = true
dns_lookup_kdc = true
[realms]
EXAMPLE.COM = {
kdc = PDC.EXAMPLE.COM
kdc = PDC2.EXAMPLE.COM
admin_server = PDC.EXAMPLE.COM
admin_server = PDC2.EXAMPLE.COM
default_domain = EXAMPLE.COM
}
[domain_realm]
.kerberos.server = EXAMPLE.COM
.example.com = EXAMPLE.COM
example.com = EXAMPLE.COM
example = EXAMPLE.COM
[appdefaults]
pam = {
ticket_lifetime = 1d
renew_lifetime = 1d
forwardable = true
proxiable = false
retain_after_close = false
minimum_uid = 0
debug = false
}
[logging]
default = FILE:/var/log/krb5libs.log
kdc = FILE:/var/log/kdc.log
admin_server = FILE:/var/log/kadmind.log
allow_weak_crypto = true到
[libdefaults] 部分。创建 Kerberos 票据
现在您可以查询 AD 域控制器并请求 Kerberos 票据(大写是必需的)
kinit administrator@EXAMPLE.COM
smb.conf,包括 winbind use default domain = yes,不能在用户名中使用 @EXAMPLE.COM。kinit administrator 会从 smb.conf 中引入 DOMAINNAME。您可以使用任何具有域管理员权限的用户名。
验证票据
运行 klist 以验证您是否收到了令牌。您应该会看到类似以下内容
# klist
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: administrator@EXAMPLE.COM
Valid starting Expires Service principal
02/04/12 21:27:47 02/05/12 07:27:42 krbtgt/EXAMPLE.COM@EXAMPLE.COM
renew until 02/05/12 21:27:47
pam_winbind.conf
如果您收到错误消息,指出找不到 /etc/security/pam_winbind.conf,请创建该文件并添加以下内容
/etc/security/pam_winbind.conf
[global] debug = no debug_state = no try_first_pass = yes krb5_auth = yes krb5_ccache_type = FILE cached_login = yes silent = no mkhomedir = yes
有了这个设置,winbind 将在登录时即时创建用户 keytab(krb5_ccache_type = FILE)并维护它们。您可以通过登录为 AD 用户后在 shell 中运行 klist 来验证这一点,而无需运行 kinit。您可能需要为 /etc/krb5.keytab 设置其他权限,例如 640 而不是 600 才能使其正常工作(参见 FS#52621 示例)
Samba
Samba 是 SMB/CIFS 网络协议的免费软件重新实现。它还包含 Linux 机器充当 Windows 网络服务器和客户端的工具。
在本节中,我们将首先通过编辑“Global”部分来着重于实现身份验证。稍后,我们将返回并添加共享。
/etc/samba/smb.conf
[Global] netbios name = MYARCHLINUX workgroup = EXAMPLE realm = EXAMPLE.COM server string = %h Arch Linux Host security = ads encrypt passwords = yes password server = pdc.example.com client signing = auto server signing = auto idmap config * : backend = tdb idmap config * : range = 10000-20000 winbind use default domain = Yes winbind enum users = Yes winbind enum groups = Yes winbind nested groups = Yes winbind separator = + winbind refresh tickets = yes winbind offline logon = yes winbind cache time = 300 template shell = /bin/bash template homedir = /home/%D/%U preferred master = no dns proxy = no wins server = pdc.example.com wins proxy = no inherit acls = Yes map acl inherit = Yes acl group control = yes load printers = no debug level = 3 use sendfile = no
加入域
您需要一个 AD 管理员帐户才能执行此操作。让我们假设它名为 Administrator。命令是“net ads join”
# net ads join -U Administrator
Administrator's password: xxx Using short domain name -- EXAMPLE Joined 'MYARCHLINUX' to realm 'EXAMPLE.COM'
启动和测试服务
启动 Samba
希望您还没有重启!好的。如果您处于 X 会话中,请退出它,这样您就可以在仍登录的情况下测试登录到另一个控制台。
启用并启动 individual Samba 守护进程 smbd.service、nmbd.service 和 winbindd.service。
smbd.service、nmbd.service 和 winbindd.service 重命名为 smb.service、nmb.service 和 winbind.service。接下来,我们需要修改 NSSwitch 配置,它告诉 Linux 主机如何从各种来源检索信息以及以何种顺序检索。在这种情况下,我们将 Active Directory 添加为用户、组和主机的附加来源。
/etc/nsswitch.conf
passwd: files winbind shadow: files winbind group: files winbind hosts: files dns wins
测试 Winbind
让我们检查 Winbind 是否能够查询 AD。以下命令应返回 AD 用户列表
# wbinfo -u
administrator guest krbtgt test.user
- 请注意,我们在域控制器上创建了一个名为“test.user”的 Active Directory 用户
我们也可以对 AD 组执行相同的操作
# wbinfo -g
domain computers domain controllers schema admins enterprise admins cert publishers domain admins domain users domain guests group policy creator owners ras and ias servers allowed rodc password replication group denied rodc password replication group read-only domain controllers enterprise read-only domain controllers dnsadmins dnsupdateproxy
测试 nsswitch
为了确保我们的主机能够查询域以获取用户和组,我们通过发出 'getent' 命令来测试 nsswitch 设置。
以下输出显示了标准 Arch Linux 安装的样子
# getent passwd
root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/bin/false daemon:x:2:2:daemon:/sbin:/bin/false mail:x:8:12:mail:/var/spool/mail:/bin/false ftp:x:14:11:ftp:/srv/ftp:/bin/false http:x:33:33:http:/srv/http:/bin/false nobody:x:99:99:nobody:/:/bin/false dbus:x:81:81:System message bus:/:/bin/false ntp:x:87:87:Network Time Protocol:/var/empty:/bin/false avahi:x:84:84:avahi:/:/bin/false administrator:*:10001:10006:Administrator:/home/EXAMPLE/administrator:/bin/bash guest:*:10002:10007:Guest:/home/EXAMPLE/guest:/bin/bash krbtgt:*:10003:10006:krbtgt:/home/EXAMPLE/krbtgt:/bin/bash test.user:*:10000:10006:Test User:/home/EXAMPLE/test.user:/bin/bash
以及组
# getent group
root:x:0:root bin:x:1:root,bin,daemon daemon:x:2:root,bin,daemon sys:x:3:root,bin adm:x:4:root,daemon tty:x:5: disk:x:6:root lp:x:7:daemon mem:x:8: kmem:x:9: wheel:x:10:root ftp:x:11: mail:x:12: uucp:x:14: log:x:19:root utmp:x:20: locate:x:21: rfkill:x:24: smmsp:x:25: http:x:33: games:x:50: network:x:90: video:x:91: audio:x:92: optical:x:93: floppy:x:94: storage:x:95: scanner:x:96: power:x:98: nobody:x:99: users:x:100: dbus:x:81: ntp:x:87: avahi:x:84: domain computers:x:10008: domain controllers:x:10009: schema admins:x:10010:administrator enterprise admins:x:10011:administrator cert publishers:x:10012: domain admins:x:10013:test.user,administrator domain users:x:10006: domain guests:x:10007: group policy creator owners:x:10014:administrator ras and ias servers:x:10015: allowed rodc password replication group:x:10016: denied rodc password replication group:x:10017:krbtgt read-only domain controllers:x:10018: enterprise read-only domain controllers:x:10019: dnsadmins:x:10020: dnsupdateproxy:x:10021:
测试 Samba 命令
尝试一些 net 命令,看看 Samba 是否可以与 AD 通信
# net ads info
[2012/02/05 20:21:36.473559, 0] param/loadparm.c:7599(lp_do_parameter) Ignoring unknown parameter "idmapd backend" LDAP server: 192.168.1.2 LDAP server name: PDC.example.com Realm: EXAMPLE.COM Bind Path: dc=EXAMPLE,dc=COM LDAP port: 389 Server time: Sun, 05 Feb 2012 20:21:33 CST KDC server: 192.168.1.2 Server time offset: -3
# net ads lookup
[2012/02/05 20:22:39.298823, 0] param/loadparm.c:7599(lp_do_parameter)
Ignoring unknown parameter "idmapd backend"
Information for Domain Controller: 192.168.1.2
Response Type: LOGON_SAM_LOGON_RESPONSE_EX
GUID: 2a098512-4c9f-4fe4-ac22-8f9231fabbad
Flags:
Is a PDC: yes
Is a GC of the forest: yes
Is an LDAP server: yes
Supports DS: yes
Is running a KDC: yes
Is running time services: yes
Is the closest DC: yes
Is writable: yes
Has a hardware clock: yes
Is a non-domain NC serviced by LDAP server: no
Is NT6 DC that has some secrets: no
Is NT6 DC that has all secrets: yes
Forest: example.com
Domain: example.com
Domain Controller: PDC.example.com
Pre-Win2k Domain: EXAMPLE
Pre-Win2k Hostname: PDC
Server Site Name : Office
Client Site Name : Office
NT Version: 5
LMNT Token: ffff
LM20 Token: ffff
# net ads status -U administrator%password | less
objectClass: top objectClass: person objectClass: organizationalPerson objectClass: user objectClass: computer cn: myarchlinux distinguishedName: CN=myarchlinux,CN=Computers,DC=leafscale,DC=inc instanceType: 4 whenCreated: 20120206043413.0Z whenChanged: 20120206043414.0Z uSNCreated: 16556 uSNChanged: 16563 name: myarchlinux objectGUID: 2c24029c-8422-42b2-83b3-a255b9cb41b3 userAccountControl: 69632 badPwdCount: 0 codePage: 0 countryCode: 0 badPasswordTime: 0 lastLogoff: 0 lastLogon: 129729780312632000 localPolicyFlags: 0 pwdLastSet: 129729764538848000 primaryGroupID: 515 objectSid: S-1-5-21-719106045-3766251393-3909931865-1105 ...<snip>...
配置 PAM
现在我们将更改 PAM 中的各种规则,以允许 Active Directory 用户使用系统进行登录和 sudo 访问等操作。在更改规则时,请注意这些项目的顺序以及它们是被标记为required还是sufficient对于事物的正常运行至关重要。除非您知道如何编写 PAM 规则,否则不应偏离这些规则。
在登录的情况下,PAM 应该首先询问 AD 帐户,如果未找到匹配的 AD 帐户,则询问本地帐户。因此,我们将条目添加到以包含 pam_winbind.so 到身份验证过程中。
Arch Linux PAM 配置在 /etc/pam.d/system-auth 中维护中心身份验证过程。从 pambase 的标准配置开始,将其更改为如下所示
system-auth
"auth" 部分
找到行
auth required pam_unix.so ...
删除它,并替换为
auth [success=1 default=ignore] pam_localuser.so auth [success=2 default=die] pam_winbind.so auth [success=1 default=die] pam_unix.so nullok auth requisite pam_deny.so
"account" 部分
找到行
account required pam_unix.so
保留它,并在下面添加此项
account [success=1 default=ignore] pam_localuser.so account required pam_winbind.so
"password" 部分
找到行
password required pam_unix.so ...
删除它,并替换为
password [success=1 default=ignore] pam_localuser.so password [success=2 default=die] pam_winbind.so password [success=1 default=die] pam_unix.so sha512 shadow password requisite pam_deny.so
"session" 部分
找到行
session required pam_unix.so
保留它,并在它上面立即添加此行
session required pam_mkhomedir.so skel=/etc/skel/ umask=0022
在 pam_unix 行下方,添加这些
session [success=1 default=ignore] pam_localuser.so session required pam_winbind.so
passwd
"password" 部分
为了让已登录的 Active Directory 用户能够使用 'passwd' 命令更改其密码,/etc/pam.d/passwd 文件必须包含 system-auth 的信息。
找到行
password required pam_unix.so sha512 shadow nullok
删除它,并替换为
password include system-auth
测试登录
现在,启动一个新的控制台会话(或 ssh)并尝试使用 AD 凭据登录。域名称是可选的,因为它已在 Winbind 配置中设置为“default realm”。请注意,对于 ssh,您需要修改 /etc/ssh/sshd_config 文件以允许 Kerberos 认证(KerberosAuthentication yes)。
test.user EXAMPLE+test.user
两者都应该有效。您应该会注意到 /home/example/test.user 将自动创建。使用 Linux 帐户登录另一个会话。检查您是否仍然可以以 root 用户身份登录 - 但请记住至少在一个会话中以 root 用户身份登录!
配置共享
之前我们跳过了共享配置。现在一切正常,请返回 /etc/samba/smb.conf,并添加您希望在 Windows 网络上可用的主机的导出。
/etc/samba/smb.conf
[MyShare] comment = Example Share path = /srv/exports/myshare read only = no browseable = yes valid users = @NETWORK+"Domain Admins" NETWORK+test.user
在上面的示例中,关键词NETWORK是要使用的。不要错误地将其替换为您的域名称。对于添加组,在组前面加上'@'符号。请注意,Domain Admins 用引号括起来,以便 Samba 在读取配置文件时正确解析它。
添加机器 keytab 文件并启用无密码的 Kerberized SSH 到机器
这解释了如何生成机器 keytab 文件,您需要该文件,例如,以启用从域中的其他机器到您的机器的无密码 Kerberized SSH。设想的场景是您在域中有许多系统,并且您刚刚向域添加了一台服务器/工作站(如上述描述),许多用户需要 SSH 到该工作站才能工作 - 例如,GPU 工作站或 OpenMP 计算节点等。在这种情况下,您可能不想每次登录时都输入密码。另一方面,在这种情况下,许多用户使用的密钥认证无法为您提供必要的凭据,例如挂载 Kerberized NFSv4 共享。因此,这将帮助您启用从客户端到相关机器的 Kerberos 票据转发的无密码登录。
创建机器 keytab 文件
以 root 身份运行 'net ads keytab create -U administrator' 以在 /etc/krb5.keytab 中创建机器 keytab 文件。它会提示您警告我们需要在配置文件中启用 keytab 认证,所以我们将在下一步中这样做。在我看来,当 key tab 文件已存在时,它会出现问题 - 命令只是不返回,它挂起了......在这种情况下,您应该重命名现有的 /etc/krb5.keytab 并再次运行该命令 - 它现在应该可以工作了。
# net ads keytab create -U administrator
通过运行以下命令验证您的 keytab 的内容
# klist -k /etc/krb5.keytab
Keytab name: FILE:/etc/krb5.keytab KVNO Principal ---- -------------------------------------------------------------------------- 4 host/myarchlinux.example.com@EXAMPLE.COM 4 host/myarchlinux.example.com@EXAMPLE.COM 4 host/myarchlinux.example.com@EXAMPLE.COM 4 host/myarchlinux.example.com@EXAMPLE.COM 4 host/myarchlinux.example.com@EXAMPLE.COM 4 host/MYARCHLINUX@EXAMPLE.COM 4 host/MYARCHLINUX@EXAMPLE.COM 4 host/MYARCHLINUX@EXAMPLE.COM 4 host/MYARCHLINUX@EXAMPLE.COM 4 host/MYARCHLINUX@EXAMPLE.COM 4 MYARCHLINUX$@EXAMPLE.COM 4 MYARCHLINUX$@EXAMPLE.COM 4 MYARCHLINUX$@EXAMPLE.COM 4 MYARCHLINUX$@EXAMPLE.COM 4 MYARCHLINUX$@EXAMPLE.COM
启用 keytab 认证
现在您需要通过将以下行添加到 /etc/samba/smb.conf 来告诉 winbind 使用该文件
kerberos method = secrets and keytab dedicated keytab file = /etc/krb5.keytab
它看起来应该像这样
/etc/samba/smb.conf
[Global] netbios name = MYARCHLINUX workgroup = EXAMPLE realm = EXAMPLE.COM server string = %h Arch Linux Host security = ads encrypt passwords = yes password server = pdc.example.com kerberos method = secrets and keytab dedicated keytab file = /etc/krb5.keytab idmap config * : backend = tdb idmap config * : range = 10000-20000 winbind use default domain = Yes winbind enum users = Yes winbind enum groups = Yes winbind nested groups = Yes winbind separator = + winbind refresh tickets = yes template shell = /bin/bash template homedir = /home/%D/%U preferred master = no dns proxy = no wins server = pdc.example.com wins proxy = no inherit acls = Yes map acl inherit = Yes acl group control = yes load printers = no debug level = 3 use sendfile = no
重启 winbindd.service
通过运行以下命令获取系统的机器票据来检查一切是否正常
# kinit MYARCHLINUX$ -kt /etc/krb5.keytab
这应该不会给出任何反馈,但运行 'klist' 应该会显示类似以下内容
# klist
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: MYARCHLINUX$@EXAMPLE.COM
Valid starting Expires Service principal
02/04/12 21:27:47 02/05/12 07:27:42 krbtgt/EXAMPLE.COM@EXAMPLE.COM
renew until 02/05/12 21:27:47
这里一些常见的错误是 a) 忘记尾部的 $ 或 b) 忽略大小写敏感性 - 它需要与 keytab 中的条目完全匹配(通常您不会出错,因为所有都是大写)
准备服务器上的 sshd
我们只需要向我们的 sshd_config 添加一些选项并重启 sshd.service。
编辑 /etc/ssh/sshd_config,使其在适当的位置看起来像这样
# /etc/ssh/sshd_config
... # Change to no to disable s/key passwords ChallengeResponseAuthentication no # Kerberos options KerberosAuthentication yes #KerberosOrLocalPasswd yes KerberosTicketCleanup yes KerberosGetAFSToken yes # GSSAPI options GSSAPIAuthentication yes GSSAPICleanupCredentials yes ...
重启 sshd.service。
在客户端添加必要的选项
首先,我们需要确保客户端上的票据是可转发(forwardable)的。这通常是标准设置,但我们最好还是检查一下。您需要查找 forwardable 选项并将其设置为 'true' 在 Kerberos 配置文件 /etc/krb5.conf 中
forwardable = true
其次,我们需要添加选项
GSSAPIAuthentication yes GSSAPIDelegateCredentials yes
到我们的 .ssh/config 文件中,以告知 ssh 使用这些选项 - 或者,可以使用 -o 选项直接在 ssh 命令中调用它们(有关帮助,请参阅 ssh(1))。
测试配置
在客户端
确保您拥有有效的票据 - 如果不确定,请运行 'kinit'
然后使用 ssh 连接到您的机器
ssh myarchlinux.example.com
您应该能够连接而无需输入密码。
如果您另外启用了密钥认证,则应执行
ssh -v myarchlinux.example.com
以查看它实际使用的认证方法。
为了调试,您可以在服务器上启用 DEBUG3 并在使用 journalctl 查看日志。
用于完整密码-Kerberos 处理的巧妙微调。
如果您的客户端出于某种原因不在本地计算机上使用域帐户,那么教会他们在使用 ssh 连接工作站之前先 kinit 可能会很困难。因此,我找到了一种很好的解决方案
生成被 AD 接受的用户 Keytabs
在一个系统上,让用户运行
ktutil addent -password -p username@EXAMPLE.COM -k 1 -e RC4-HMAC - enter password for username - wkt username.keytab q
现在通过调用以下命令来测试文件
kinit username@EXAMPLE.COM -kt username.keytab
它不应该提示您输入密码,也不应该提供任何其他反馈。如果它有效,您基本上就完成了——只需将上面的那一行放入您的 ~/.bashrc 中——您现在就可以在不输入密码的情况下获取 Kerberos 票证,然后您就可以在不输入密码的情况下连接到您的工作站,同时完全 Kerberos 化,并能够通过票证对 NFSv4 和 CIFS 进行身份验证——非常方便。
值得了解
文件 'username.keytab' 不是机器特定的,因此可以到处复制。例如,我们在 Linux 机器上创建了文件,并将其复制到我们的 Mac 客户端,因为 Mac 上的命令不同……
参见
- 维基百科 - Active Directory
- 维基百科 - Samba
- 维基百科 - Kerberos
- Samba - 文档
- Samba Wiki 上的目录
- Samba Wiki - Samba、Active Directory & LDAP
- smb.conf(5)
使用 SSSD
sssd 可以代替 Samba 与 AD 集成。请参阅 SSSD 文档。
商业解决方案
- Centrify
- Likewise
开源版本
- PowerBroker Identity Services Open:前身为 Likewise,后被 BeyondTrust 收购
- Centrify Express for Linux