I ran into enough snags when attempting to join an CentOS 6.6 machine to a Microsoft domain that I thought I would document them here. Hopefully it is of use to someone. The majority of the experience is thanks to this site.
Update 03/16/2015: I came across this site which makes things a little easier when it comes to initial configuration – messing with other config files is no longer necessary. The authconfig command to do this is below:
authconfig --disablecache --enablelocauthorize --enablewinbind --enablewinbindusedefaultdomain --enablewinbindauth --smbsecurity=ads --enablekrb5 --enablekrb5kdcdns --enablekrb5realmdns --enablemkhomedir --enablepamaccess --updateall --smbidmapuid=100000-1000000 --smbidmapgid=100000-1000000 --disablewinbindoffline --winbindjoin=Admin_account --winbindtemplateshell=/bin/bash --smbworkgroup=DOMAIN --smbrealm=FQDN --krb5realm=FQDN
Replace DOMAIN with short domain name, FQDN with your fully qualified domain name, and Admin_account with an account with domain admin privileges, then skip to the Reboot section, as it covers everything before that.
Install the necessary packages
yum -y install authconfig krb5-workstation pam_krb5 samba-common oddjob-mkhomedir
Configure kerberos auth with authconfig
There is a curses-based GUI you can use to do this in but I opted for the command line.
authconfig --disablecache --enablewinbind --enablewinbindauth --smbsecurity=ads --smbworkgroup=DOMAIN --smbrealm=DOMAIN.COM.AU --enablewinbindusedefaultdomain --winbindtemplatehomedir=/home/DOMAIN/%U --winbindtemplateshell=/bin/bash --enablekrb5 --krb5realm=DOMAIN.COM.AU --enablekrb5kdcdns --enablekrb5realmdns --enablelocauthorize --enablemkhomedir --enablepamaccess --updateall
Add your domain to kerberos configuration
Kerberos information is stored in /etc/krb5.conf. Append your domain in the realms configuration, like below
vi /etc/krb5.conf
[realms] EXAMPLE.COM = { kdc = kerberos.example.com admin_server = kerberos.example.com } DOMAIN.COM.AU = { admin_server = DOMAIN.COM.AU kdc = DC1.DOMAIN.COM.AU kdc = DC2.DOMAIN.COM.AU } [domain_realm] .example.com = EXAMPLE.COM example.com = EXAMPLE.COM domain.com.au = DOMAIN.COM.AU .domain.com.au = DOMAIN.COM.AU
Test your configuration
Use the kinit command with a valid AD user to ensure a good connection with the domain controllers:
kinit <AD user account>
klist Ticket cache: FILE:/tmp/krb5cc_0 Default principal: someaduser@DOMAIN.COM.AU Valid starting Expires Service principal 02/27/14 12:23:21 02/27/14 22:23:21 krbtgt/DOMAIN.COM.AU@DOMAIN.COM.AU renew until 03/06/14 12:23:19
kinit: KDC reply did not match expectations while getting initial credentials
Join the domain
net ads join domain.com.au -U someadadmin
Our netbios name can be at most 15 chars long, "EXAMPLEMACHINE01" is 16 chars long Invalid configuration. Exiting.... Failed to join domain: The format of the specified computer name is invalid.
vi /etc/samba/smb.conf
netbios name = EXAMPLE01
net ads testjoin
Configure home directories
The authconfig command above included a switch for home directories. Make sure you create a matching directory and set appropriate permissions for it.
mkdir /home/DOMAIN setfacl -m group:"Domain Users":rwx /home/DOMAIN #the article calls to do this, this command doesn't work for me but home directories still appear to be created properly
Reboot
To really test everything the best way is to reboot the machine. When it comes back up, log in with Active Directory credentials. It should work!
Account lockout issues
I ran into a very frustrating problem where everything works dandy if you get the password correct on the first try, but if you mess up even once it results in your Active Directory account being locked. You were locked out after the first try. Each login, even when successful, had this in the logs:
winbind pam_unix(sshd:auth): authentication failure
This problem took a few days to solve. Ultimately it involved modifying two files:
vi /etc/pam.d/system-auth vi /etc/pam.d/password-auth
As far as I can tell, the problem was a combination of pam_unix being first (which always failed when using AD login), as well as having both winbind and kerberos enabled. The fix was to change the order of each mention of pam_unix to be below any mention of pam_winbind. The other fix I had to do was to comment out mentions of pam_krb5 completely.
#auth sufficient pam_krb5.so use_first_pass
Restrict logins
The current configuration allows any domain account to log into the machine. You will probably want to restrict who can log in to the machine to certain security groups. The problem: many Active Directory security groups contain spaces in their name, which Linux doesn’t like.
How do you add a security group that contains a space? Escape characters don’t seem to work in the pam config files. I found out thanks to this site that it is easier to just not use spaces at all. Get the SID of the group instead.
Use wbcinfo -n to query the group in question, using the backslash to escape the space. It will return the SID we desire.
wbinfo -n Domain\ Users S-1-5-21-464601995-1902203606-794563710-513 Domain Group (2)
Next, modify /etc/pam.d/password-auth and add the require_membership_of argument to pam_winbind.so:
auth sufficient pam_winbind.so require_membership_of=S-1-5-21-464601995-1902203606-794563710-513
That’s it! Logins are now restricted to the security group listed.
Configure sudo access
Sudo uses a different list for authorization, which amusingly, handles escaped spaces just fine. Simply add the active directory group in sudo as you a local one, eg using a % and then group name, escaping spaces with a backslash:
%Domain\ Users ALL=(ALL) ALL
Rejoice
You’ve just gone through a long and painful battle. Hopefully this article helped you to achieve victory.