Integrating RHEL with Active Directory

I had a request on Reddit to share a document I wrote about connect Red Hat Enterprise Linux with Active Directory. The original document I wrote is confidential, but I said I would write it up.

This works for both Server 2008(R2) and 2012. If I recall correctly it will also work with 2003, but may need to minor terminology changes on the Windows side. From the Linux side, it should be fine with RHEL 6 and similar (CentOS and Scientific Linux). It should also apply to Fedora, but your mileage may vary.

So without further ado, let\'s dive in. To do this you need to know what is actually happening under the surface when you authenticate to AD from a client. The basic idea looks something like this:


Integration with AD requires the installation of a few services in Red Hat, along with some minor modifications on the Windows Domain Controllers. On the Linux side, everything revolves around the System Security Services Daemon (SSSD). All communication between the PAM and the various possible back-ends is brokered through this daemon. This is only one solution, there are several. The others involve Winbind (which I have found problematic), or LDAP/Kerberos directly (no offline authentication, more difficult to set up). Note that this does not give you any file sharing, but can easily be extended to do so using Samba.

PAM communicates with SSSD, which in turn talks to Active Directory via LDAP and Kerberos. Identification is performed via LDAP, with the user is authenticated using Kerberos. These different components have some prerequisites on Windows.

For both DNS and NTP I\'m assuming that you are using the services provided by Active Directory. It is possible to break those out to other boxes, but it beyond my Windows Admin ability/desire to do so.

Preparing Active Directory

In Server Manager, add the Role Service \"Identity Management for UNIX\". This is under the Role \"Active Directory Domain Services\" (took me a while to find that). When it asks, use your AD domain name as the NIS name. For example, with a AD domain of chriscowley.lab, use chriscowley.

Once that is installed, create a pair of groups. For the sake of argument, lets call them LinuxAdmin and LinuxUser. The intended roles of these 2 groups is left as an exercise for the reader. When you create these groups, you will see a new tab in the properties window for both groups and users: \"UNIX Attributes\".

Now go ahead and create a user (or edit an existing one). Go into the UNIX tab and set the configure the user for UNIX access:


Open up one of your groups (let\'s start with LinuxAdmin) and add the user to that group. Note you have to do it 2 places (don\'t blame me, I am just the messenger). Both in the standard Groups tab, but also in the UNIX attributes tab.

That should be everything on the Windows side.

Configure RHEL as a client

Most of the heavy lifting is done by the System Security Service Daemon (SSSD).

yum install sssd sssd-client krb5-workstation samba openldap-clients policycoreutils-python

This should also pull in all the dependencies.

Configure Kerberos

I\'ve already said, this but I will repeat myself as getting it wrong will cause many lost hours.

Make sure that /etc/resolv.conf contains your domain controllers.

Gotcha: In RHEL/Fedora the DNS setting are defined in /etc/sysconfig/network-settings/ifcfg-eth0 (or whichever NIC comes first) by Anaconda. This will over-write /etc/resolv.conf on reboot. For no good reason other than stubbornness I tend to remove these entries and define resolv.conf myself (or via configuration management). Alternatively put DNS1 and DNS2 entries in the network configuration files.

In /etc/krb5.conf change you servers to point at your Domain Controllers.

 default = FILE:/var/log/krb5libs.log

 default_realm = AD.EXAMPLE.COM
 dns_lookup_realm = true
 dns_lookup_kdc = true
 ticket_lifetime = 24h
 renew_lifetime = 7d
 rdns = false
 forwardable = yes

  # Define the server only if DNS lookups are not working
#  kdc =
#  admin_server =

[domain_realm] = AD.EXAMPLE.COM = AD.EXAMPLE.COM

You should now be able to run:

That should obtain a kerberos ticket (check with klist) and you can move on. If it does not work fix it now - Kerberos is horrible to debug later.

Enable LDAP Searches

The best way to bind to AD is using SASL/GSSAPI as no passwords are needed.

kinit [email protected]
net ads join createupn=host/[email protected] –k
net ads keytab create   
net ads keytab add host/[email protected]

You should now be able to get information about yourself from AD using ldapsearch:

ldapsearch -H ldap:// -Y GSSAPI -N -b "dc=ad,dc=example,dc=com" "(&(objectClass=user)(sAMAccountName=aduser))"

Configure SSSD

Everything in SSSD revolves around a single config file (/etc/sssd/ssd.conf).

 config_file_version = 2
 domains =
 services = nss, pam
 debug_level = 0



 id_provider = ldap
 auth_provider = krb5 
 chpass_provider = krb5
 access_provider = ldap

 # To use Kerberos, un comment the next line
 #ldap_sasl_mech = GSSAPI

 # The following 3 lines bind to AD. Comment them out to use Kerberos
 ldap_default_bind_dn = CN=svc_unix,OU=useraccounts,DC=ad,DC=example,DC=com
 ldap_default_authtok_type = password
 ldap_default_authtok = Welcome_2014

 ldap_schema = rfc2307bis

 ldap_user_search_base = ,dc=ad,dc=example,dc=com
 ldap_user_object_class = user

 ldap_user_home_directory = unixHomeDirectory
 ldap_user_principal = userPrincipalName

 ldap_group_search_base = ou=groups,dc=ad,dc=example,dc=com
 ldap_group_object_class = group

 ldap_access_order = expire
 ldap_account_expire_policy = ad
 ldap_force_upper_case_realm = true

 krb5_realm = AD.EXAMPLE.COM

There is something wrong here. Note the lines:

# To use Kerberos, un comment the next line
#ldap_sasl_mech = GSSAPI

# The following 3 lines bind to AD. Comment them out to use Kerberos
ldap_default_bind_dn = CN=svc_unix,OU=useraccounts,DC=ad,DC=example,DC=com
ldap_default_authtok_type = password
ldap_default_authtok = Welcome_2014

Instead of doing the SASL/GSSAPI bind I would prefer to do I have chickened out and done a simple bind. Why? Because I am weak... :-(

Try with kerberos first, if it works then awesome, if not then create a service account in AD that can do nothing other than perform a search and use that to perform the bind. Make sure its path matches that of the ldap_default_bind_dn path, also make sure the password is more complex than \"Welcome_2014\".

For now this does nothing, we need to tell PAM to use it. The easiest way to enable this on RHEL is to use the authconfig command:

authconfig --enablesssd --enablesssdauth --enablemkhomedir –update

This will update /etc/nsswitch.conf and various files in /etc/pam.d to tell the system to authenticate against SSSD. SSSD will in turn talk to Active Directory, using LDAP for Identification and Kerberos for authentication. Finally you can enable your LinuxAdmin's to use sudo. Run the command visudo and add the line:

%LinuxAdmin ALL=(ALL)       ALL
# note the % sign, the defines it as a group not a user

Now your admin's can run commands as root by prefacing them with sudo. For an encore, I would suggest disabling root login via SSH. Log in as your AD user (leave your root session open, just in case) and run:

sudo sed -i 's/PermitRootLogin no/PermitRootLogin yes/' /etc/ssh/sshd_config
sudo service sshd reload