使用 AD 对 Linux 服务器进行身份验证的实用性如何?

使用 AD 对 Linux 服务器进行身份验证的实用性如何?

我们的软件开发公司同时使用 Windows 和 Linux 服务器。

这种设置的一个难点是我们没有单点登录解决方案。作为一家 Microsoft 商店而非 Linux 商店,我们希望通过 AD 进行身份验证。

我在网上读了几篇文章并且我知道这是可能的。

我们目前在 Linux 上使用以下需要身份验证的服务:
- git 服务器(通过 SSH)
- Sendmail
- 当前使用 .htaccess 文件的 Apache Web 服务器。
- SAMBA 文件共享

我想知道的是这种设置有多实用?它真的有效吗?还是容易出错?

答案1

这并不难,而且非常实用。

我们有几百台使用 AD 身份验证的双启动台式机,以及许多使用 AD 身份验证的服务器,以使 Windows 客户端能够使用其 samba 共享,而无需用户明确身份验证。

SF 上还有另一篇文章介绍您需要做什么。

基本上,您需要配置 kerberos、winbind、nss 和 pam。

然后你做 akinit和 anet ads join然后你就完成了。

如果需要,您可以将 pam 配置为使用多种方法进行身份验证,因此如果一种方法不起作用,它就会恢复到下一种方法。

我们通常使用文件、winbindd 和 ldap 作为向 Windows 服务器提供文件共享的服务器。

如果可能的话,我会使用 LDAP 来获取帐户信息,并使用 windbind 来严格进行身份验证,但我相信您可以在需要时在 /etc/ldap.conf 中映射属性。如果您最终使用 winbindd 来获取帐户信息,则可以使用 RID(散列方法)来生成 uid/gid,但也可以使用其他方法。我们在一个大型文件服务器上使用了 RID,这真的很麻烦,所以如果可能的话,我会尝试探索其他选项之一。在我们的案例中,所有 AD 用户和组都由上游 IDM 系统反映在 LDAP 中,因此我们在较新的服务器上使用 LDAP 来获取帐户信息,并使用 winbind 纯粹进行身份验证。

答案2

使用 Likewise Open 进行身份验证非常简单。http://www.likewise.com/products/likewise_open/index.php

得益于 Likewise Open,我的几乎整个 Linux 基础架构都实现了集中身份验证和用户管理。它的安装和实施非常简单。我对它赞不绝口。

值得注意的是,UID 和 GID 是根据哈希函数分配的,因此它们在整个基础设施中是相同的,因此 NFS 挂载可以完美运行。

答案3

我安装了 Windows Services for Unix,并在 AD 中添加了一个名为“Unix Authenticator”的用户,然后在 Linux 机器上进行了以下配置文件更改:

/etc/ldap.conf:
host ldap.<foo>.com
base cn=Users,dc=<foo>,dc=com
binddn cn=Unix Authenticator,cn=Users,dc=<foo>,dc=com
bindpw <password>
nss_base_passwd cn=Users,dc=<foo>,dc=com?sub
nss_base_shadow cn=Users,dc=<foo>,dc=com?sub
nss_base_group cn=Users,dc=<foo>,dc=com?sub
nss_map_objectclass posixAccount User
nss_map_objectclass shadowAccount User
nss_map_objectclass posixGroup Group
nss_map_attribute cn msSFUName
nss_map_attribute uid msSFUName
nss_map_attribute gid gidNumber
nss_map_attribute gecos sAMAccountName
nss_map_attribute homeDirectory msSFUHomeDirectory
nss_map_attribute uniqueMember Member
pam_login_attribute msSFUName
pam_filter objectclass=user
pam_password ad
/etc/ldap.secret:
<password>
/etc/nsswitch.conf:
passwd: compat ldap
shadow: compat ldap
group: compat ldap
/etc/nsswitch.ldap:
host files dns
/etc/pam.d/系统身份验证:
auth required /lib/security/pam_env.so
auth sufficient /lib/security/pam_unix.so likeauth nullok
auth sufficient /lib/security/pam_ldap.so use_first_pass
auth required /lib/security/pam_deny.so

account sufficient /lib/security/pam_ldap.so
account required /lib/security/pam_unix.so

password required /lib/security/pam_cracklib.so retry=3
password sufficient /lib/security/pam_unix.so nullok md5 shadow use_authtok
password sufficient /lib/security/pam_ldap.so use_first_pass use_authtok
password required /lib/security/pam_deny.so

session required /lib/security/pam_limits.so
session required /lib/security/pam_unix.so

希望这可以帮助。

答案4

您不需要使用 Samba,AD 直接支持 Kerberos 和 LDAP。在大多数发行版上,您没有理由使用任何外部软件。

对于 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

相关内容