Active Directory 集成
来自 维基百科
本文介绍如何使用 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 进行名称解析。务必使用正确的 DNS 服务器和域搜索后缀配置 /etc/resolv.conf
文件。无论是通过 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
启动各个 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_unix.so 的所有条目用于 pam_winbind.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 配置中设置为“默认领域”。请注意,对于 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 使用 轻型目录访问协议 (LDAP) 版本 2 和 3、Microsoft 版本的 Kerberos 和 DNS。
术语
如果您不熟悉 Active Directory,那么了解一些关键字很有帮助。
- 域 :用于对计算机和帐户进行分组的名称。
- SID :加入域作为成员的每台计算机都必须具有唯一的 SID 或系统标识符。
- SMB :服务器消息块。
- 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 > 计算机设置 > 策略 > Windows 设置 > 安全设置 > 本地策略 > 安全选项 > Microsoft 网络客户端:数字签名通信(始终)中修改它。
请注意,禁用此 GPO 会影响域中所有成员的安全性。
Linux 主机配置
接下来的几个步骤将开始配置主机的过程。您将需要 root 或 sudo 访问权限才能完成这些步骤。
安装
安装 以下软件包
更新 DNS
Active Directory 严重依赖 DNS。您将需要更新 /etc/resolv.conf
以使用一个或多个 Active Directory 域控制器
/etc/resolv.conf
nameserver <IP1> nameserver <IP2>
将 <IP1> 和 <IP2> 替换为 AD 服务器的有效 IP 地址。如果您的 AD 域不允许 DNS 转发或递归,您可能需要添加其他解析器。
/etc/resolv.conf
文件中的 DNS 条目 127.0.0.53 指的是 systemd-resolved 提供的本地 DNS 解析器。如果您已使用网络管理器配置了 DNS 服务器,则此步骤是不必要的,如果按照建议修改 resolv.conf,则可能会导致问题。- 如果您的计算机双启动 Windows 和 Linux,则如果两个操作系统都将是同一域的成员,则应为 linux 配置使用不同的 DNS 主机名和 netbios 名称。
配置 NTP
阅读 系统时间#时间同步 以配置 NTP 服务。
在 NTP 服务器配置上,使用 AD 服务器的 IP 地址,因为它们通常将 NTP 作为服务运行。或者,如果 Active Directory 服务器同步到相同的层,您可以使用其他已知的 NTP 服务器。
确保将服务配置为在启动时尽早自动同步时间。
Kerberos
让我们假设您的 AD 名为 example.com。让我们进一步假设您的 AD 由两个域控制器(主域控制器和辅助域控制器)管理,它们分别名为 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 将在登录时动态创建用户密钥表 (krb5_ccache_type = FILE) 并维护它们。您可以通过在以 AD 用户身份登录后但在无需运行 kinit 的情况下在 shell 中简单地运行 klist 来验证这一点。您可能需要在 /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 会话中,请退出它,以便您可以在另一个控制台中测试登录,同时您仍然处于登录状态。
启用并启动各个 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 配置中设置为“默认领域”。请注意,对于 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 文件并激活到机器的免密码 Kerberos SSH
这解释了如何生成机器 keytab 文件,您将需要该文件,例如,启用从域中其他机器到您的机器的免密码 kerberized ssh。想到的场景是,您的域中有一堆系统,并且您刚刚使用上述描述将服务器/工作站添加到您的域,许多用户需要 ssh 进入该服务器/工作站才能工作 - 例如 GPU 工作站或 OpenMP 计算节点等。在这种情况下,您可能不想每次登录都键入密码。另一方面,在这种情况下许多用户使用的密钥身份验证不能为您提供必要的凭据,例如挂载 kerberized NFSv4 共享。因此,这将帮助您启用从客户端到相关机器的免密码登录,使用 kerberos 票据转发。
创建机器 key tab 文件
以 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 身份验证
现在您需要告诉 winbind 通过将这些行添加到 /etc/samba/smb.conf 来使用该文件
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
。
在客户端添加必要选项
首先,我们需要确保客户端上的票据是可转发的。这通常是标准的,但我们最好还是检查一下。您必须在 Kerberos 配置文件 /etc/krb5.conf
中查找 forwardable 选项并将其设置为 'true'
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 接受的用户 Keytab
在系统上,让用户运行
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 票据而无需键入密码,并且通过它,您可以连接到您的工作站而无需键入密码,同时完全 kerberized 并且能够通过票据针对 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:以前由 BeyondTrust 收购的 Likewise
- Centrify Express for Linux