Follow this article when you would like users to be able to login to a CentOS 6 host, authenticating to Active directory based on:
- Group membership of a user (a group like "Linux Administrators") (or)
- A "host" attribute set per user to allow fine grained host-based permissions
This has a major benefit. You can add users to an administrative group and besides that you can assign permissions to login to a user per host. Once you have set this up, you can manage permissions fully through Active Directory.
Install required pacakges
You need to install one single package:
yum install nss-pam-ldapd
There are quite few files to configure, I know that system-config-auth exists, but don't know if it gives the right results. So here are the files one-by-one:
# This program runs under this user and group, these are local/system (/etc/passwd) users.
# The base is where to start looking for users. Your Windows colleagues will know this value.
# This is the URI that describes how to connect to the LDAP server/active directory server. You may use a DNS round-robin name here to point to multiple Domain Controllers.
# This is a user that can authenticate to Active Directory. It's used to connect to AD and query stuff.
# Don't exactly know where I got these settings from, man-page has more information.
scope group sub
scope hosts sub
# If there are many results, paging is used.
# LDAP servers can refer you to another location, in my experience this slow down authentication dramatically.
# This is the trick to match users from a certain group and users that have a host-attribute filled in.
# Note that the value of the variable "host" should be set to the hostname where this file in installed.
filter passwd (&(objectClass=user)(!(objectClass=computer))(unixHomeDirectory=*)(|(host=mylinuxhost.nl.example.com)(memberOf=CN=Linux Administrators,OU=Groups,DC=nl,DC=example,DC=com)))
# Active Directory may store some values in attributes that need to be mapped.
map passwd homeDirectory unixHomeDirectory
filter shadow (&(objectClass=user)(!(objectClass=computer))(unixHomeDirectory=*))
map shadow shadowLastChange pwdLastSet
# This filters out groups that have a "gidNumber" set. This typically only happens for groups that need to be available on Linux.
filter group (&(objectClass=group)(gidNumber=*))
map group uniqueMember member
# Some time limits.
# Secure Socket Layer, yes we do!
This file looks very much like /etc/nslcd.conf, don't know why there are two actually. It confuses people.
nss_map_objectclass posixAccount user
nss_map_objectclass shadowAccount user
nss_map_objectclass posixGroup Group
nss_map_attribute homeDirectory unixHomeDirectory
nss_map_attribute uniqueMember member
nss_map_attribute shadowLastChange pwdLastSet
pam_groupdn CN=Linux Administrators,OU=Groups,DC=nl,DC=example,DC=com
/etc/pam.d/system-auth-ac and /etc/pam.d/password-auth-ac
These two files contain the same.
auth required pam_env.so
auth sufficient pam_unix.so nullok try_first_pass
auth requisite pam_succeed_if.so uid >= 500 quiet
auth sufficient pam_krb5.so
auth required pam_deny.so
account [default=bad user_unknown=ignore success=ok authinfo_unavail=ignore] pam_krb5.so
account required pam_unix.so
account sufficient pam_succeed_if.so uid < 500 quiet
account required pam_permit.so
password requisite pam_cracklib.so try_first_pass retry=3
password sufficient pam_unix.so md5 shadow nullok try_first_pass use_autht ok
password required pam_deny.so
session optional pam_keyinit.so revoke
session required pam_limits.so
session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session required pam_unix.so
session required pam_mkhomedir.so skel=/etc/skel umask=0077
This determines to send certain resolving queries to what facility. Make sure these lines are in:
passwd: files ldap [NOTFOUND=return UNAVAIL=return] db
shadow: files ldap [NOTFOUND=return UNAVAIL=return] db
group: files ldap [NOTFOUND=return UNAVAIL=return] db
sudoers: files ldap [NOTFOUND=return UNAVAIL=return] db
Starting of daemons
When all configuration changes are done, make sure to startup nslcd:
service nslcd start
chkconfig nslcd on
There is a caching mechanism in nslcd. I don't know how to flush that cache, but it caches negative hits too. (So when a user is not found, it will keep on saying that the user is not found) Waiting (a night) clears that cache, but this does not help you to solve the problem today.
You may stop nslcd and run in in debug mode:
service nslcd stop
This will show you all queries sent to the ldap server.
Source Me in IT.
Post a Comment