如何使用 Active Directory 验证 Linux 用户

如何使用 Active Directory 验证 Linux 用户

使用 Active Directory 对 Linux(Debian)机器上的用户进行身份验证的最佳实践是什么?

我希望它的工作方式是将 AD 用户添加到一个组中 - 比如说Linux 管理员或者Linux 网络服务器,并根据其组成员身份,授予/不授予他们访问特定服务器的权限。理想情况下,root 帐户是唯一以标准方式维护的帐户。

我这样做的目的是:

  • 允许在一个位置更改密码
  • 使用 AD 凭据自动授予某些人访问 Linux 服务器的权限
  • 将所有用户信息整合到一个数据库中

我想避免的事情是:

  • 对于我们的 Active Directory 管理员来说,任何难以管理或违反直觉的事情
  • 如果 AD 服务器由于某种原因无法访问,则锁定用户(即需要以某种方式缓存凭据)
  • 任何过于复杂或非标准的东西都会在下次升级服务器时崩溃。

答案1

答案2

在大多数发行版中您没有理由使用任何外部软件。

对于 Debian/Ubuntu,您可以使用 libnss-ldap 和 libpam-krb5 来实现。有一些技巧可以 100% 实现。这假设您为 Linux 用户填充了“unixHomeDirectory”,您的 Linux 计算机使用与 Windows 系统通用的 NTP(Kerberos 要求),并且您可以使用纯文本 NSS 查找(不是密码而是组成员信息等 - 您也可以使用 TLS,但设置起来更复杂)。除非您设置为使用 TLS,否则您不应该在 PAM 中使用 pam_ldap 作为密码或身份验证源。

/etc/ldap.conf

# LDAP Configuration for libnss-ldap and libpam-ldap.
# Permit host to continue boot process with out contacting LDAP server
bind_policy soft
# Define LDAP servers to use for queries, these must be Global Catalog servers
uri ldap://ldap.site.company.local
# Define root search location for queries
base dc=company,dc=local
#debug 1
# LDAP version, almost always going to be v3, it is quite mature
ldap_version 3
# Username used to proxy authentication. You can have this in a separate file owned by root for security OR use TLS/SSL (see man page)
# Do NOT use LDAP for authentication if you are using plain text binds, use Kerberos instead (and LDAP for authorization only). See libpam-krb5.
binddn cn=ldap-auth-svc,ou=ldap,ou=services,dc=site,dc=company,dc=local
# Password for proxy acct
bindpw SooperSekeretPazzwerd
#  TCP port to perform queries on, 3268 is a Global Catalog port which will reply for all users in *.company.local
port 3268
# Search range scope (sub = all)
scope sub
# Tell the client to close TCP connctions after 30 seconds, Windows will do this on the server side anyways, this will prevent errors from showing up in the logs.
 idle_timelimit 30
# Expect queries for group membership to return DN for group members instead of usernames (lets you use MSAD group membership seamlessly)
nss_schema rfc2307bis
# Filters - User accounts must have a UID >= 2000 to be recognized in this configuration and must have a unixHomeDirectory defined.
nss_base_group dc=company,dc=local?sub?&(objectClass=group)(gidNumber=*)
nss_base_user dc=company,dc=local?sub?&(objectClass=user)(!(objectClass=localputer))(uidNumber>=2000)(unixHomeDirectory=*)
nss_base_shadow dc=company,dc=local?sub?&(objectClass=user)(!(objectClass=localputer))(uidNumber>=2000)(unixHomeDirectory=*)
# Object Class mappings.  You may want to have the posixAccount to map to "mail" and have users login with their email addresses, i.e.  "nss_map_objectclass posixAccount mail".
nss_map_objectclass posixAccount user
nss_map_objectclass shadowAccount user
nss_map_objectclass posixGroup group
# Attribute mappings.
nss_map_attribute uniqueMember member
nss_map_attribute uid sAMAccountName
nss_map_attribute homeDirectory unixHomeDirectory
nss_map_attribute shadowLastChange pwdLastSet
# Attribute in LDAP to query to match the username used by PAM for authentication
pam_login_attribute sAMAccountName
# Filter for objects which are allowed to login via PAM
pam_filter objectclass=User

假设您的 Linux 机器正在使用了解 AD 的 DNS 服务器(具有适当 SRV 记录的 _msdcs 区域是可解析的),那么您不需要编辑 /etc/krb5.conf

/etc/nsswitch.conf 应该包含用户、组、影子等“ldap 文件”。

对于使用 SSSD 的 Red Hat:

/etc/sssd/sssd.conf

[domain/AD]
id_provider = ldap
auth_provider = krb5
chpass_provider = krb5
access_provider = ldap

ldap_uri = ldap://ldap.company.local:3268/
ldap_search_base = dc=company,dc=com
ldap_default_bind_dn = cn=ldap-auth-svc,ou=ldap,ou=services,dc=site,dc=company,dc=local
ldap_default_authtok = SooperSekeretPazzwerd
ldap_schema = rfc2307bis
ldap_user_object_class = user
ldap_group_object_class = group
ldap_user_name = sAMAccountName
ldap_user_home_directory = unixHomeDirectory
enumerate = true
ldap_tls_reqcert = never
ldap_tls_cacertdir = /etc/openldap/cacerts

ldap_id_use_start_tls = False
cache_credentials = True
krb5_realm = SITE.COMPANY.COM
case_sensitive = false
[sssd]
services = nss, pam
config_file_version = 2

domains = AD
[nss]
filter_users = root,named,avahi,nscd

答案3

您正在寻找的软件叫做 Likewise-open。

来自他们的页面:

  • 通过命令行或 GUI 只需一步即可将非 Windows 系统加入 Active Directory 域
  • 在 Windows 和非 Windows 上使用单个用户名和密码对用户进行身份验证
  • 对非 Windows 用户和 Windows 用户强制实施相同的密码策略
  • 通过单向和双向跨林信任支持多个林
  • 在域控制器发生故障时缓存凭据
  • 为 SSH 和 Putty 提供单点登录
  • 支持 Kerberos、NTLM 和 SPNEGO 的下一代身份验证引擎
  • 无需对 Active Directory 进行架构更改

我们已经在一些机器上使用过它,而且似乎运行良好。

http://www.likewise.com/products/likewise_open/

答案4

您应该评估 Radius。配置 Linux 系统以使用 pam-radius 并安装 MS radius 插件 NPS。它将与 AD 通信。您可以在此处的 pdf 电子指南中获取概述:http://www.wikidsystems.com/learn-more/two-factor-authentication-white-papers(无需注册)。只需忽略双因素身份验证位即可。

相关内容