UPDATE: These instructions are for Windows 2000 Server and Windows Server 2003 pre-R2. For the R2 release, please see these updated instructions.
There are several articles posted here that discuss, in general terms, how to authenticate Linux against Active Directory. For example, see this brief article on the broad direction of the integration, or this posting on using computer accounts for Linux servers (most how-to documents I’ve seen discuss the use of a user account for this purpose).
Over the last week or so, I’ve been having to rebuild one Linux server a number of times in an effort to fix a separate problem (see this article on NTPd problems with CentOS 4.1 and the recurrence of the problem with CentOS 4.2). As a result, I’ve had to go through the process of configuring this Linux server (and preparing Active Directory) for authentication several times, and I found that I kept having to go back to my scattered and dispersed notes to remember what had to be done. In the hopes of correcting that, I am collecting all the pertinent information I have here in this article.
Preparing Active Directory (One-Time)
There is a one-time preparation of Active Directory that is required. In order to authenticate Linux logins against Active Directory, Active Directory’s schema must be extended to include Linux-specific attributes such as home directory, UID, GID, and default shell. There are a couple of different ways to do this; I chose to use Microsoft’s Services for Unix (SFU) to extend the schema. There are two reasons I chose SFU: 1) it’s free; and 2) the SFU schema is being included by default in Windows Server 2003 R2.
Once SFU has been installed and the schema has been extended, then the specific Active Directory accounts that are allowed to authenticate via Linux must be configured with a UID and other UNIX attributes. This is accomplished via the new “UNIX Attributes†tab on the properties dialog box of a user account.
You’ll also need to create an account in Active Directory that will be used to bind to Active Directory for LDAP queries. This account does not need any special privileges; in fact, making the account a member of Domain Guests and not a member of Domain Users is perfectly fine.
After all the user accounts have been configured, then we are ready to perform the additional tasks within Active Directory and on the Linux server that will enable the authentication.
Preparing Active Directory (Each Server)
For each server that will be authenticating against Active Directory, follow the steps below.
- Create a computer account in Active Directory. When creating the computer account, be sure to specify that this account may be used by a pre-Windows 2000–based computer.
- Use the following command at a command prompt to configure the new computer account:
ktpass -princ host/fqdn@REALM -mapuser DOMAIN\name$
-crypto DES-CBC-MD5 -pass password -ptype KRB5_NT_PRINCIPAL
-out filename
Of course, you’ll need to substitute the appropriate values for “fqdn†(the fully-qualified domain name of the computer), “REALM†(the DNS name of your Active Directory domain in UPPERCASE), “DOMAIN†(the NetBIOS name of your Active Directory domain), “password†(the password that will be set for the new computer account), and “filename†(the keytab that will be generated and must be copied over to the Linux computer).
If you need to rebuild the Linux server for whatever reason, you’ll need to delete the computer account you created and repeat this process.
Preparing the Linux Server
Follow the steps below to configure the Linux server for authentication against Active Directory.
- Make sure that the appropriate Kerberos libraries, OpenLDAP, pam_krb5, and nss_ldap are installed. If they are not installed, install them.
- Be sure that time is being properly synchronized between Active Directory and the Linux server in question. Kerberos requires time synchronization.
- Edit the krb5.conf file to look something like this, substituting your actual host names and domain names where appropriate:
[logging]
default = FILE:/var/log/krb5libs.log
kdc = FILE:/var/log/krb5kdc.log
admin_server = FILE:/var/log/kadmind.log
[libdefaults]
default_realm = EXAMPLE.COM
dns_lookup_realm = true
dns_lookup_kdc = true
[realms]
EXAMPLE.COM = {
kdc = host.example.com:88
admin_server = host.example.com:749
default_domain = example.com
}
[domain_realm]
.example.com = EXAMPLE.COM
example.com = EXAMPLE.COM
[kdc]
profile = /var/kerberos/krb5kdc/kdc.conf
[appdefaults]
pam = {
debug = false
ticket_lifetime = 36000
renew_lifetime = 36000
forwardable = true
krb4_convert = false
} - Edit the /etc/ldap.conf file to look something like this, substituting the appropriate host names, domain names, account names, and distinguished names (DNs) where appropriate.
host 10.10.10.10
base dc=example,dc=com
binddn cn=ldap,cn=Users,dc=example,dc=com
bindpw adldapbindpw
scope sub
ssl no
nss_base_passwd dc=example,dc=com
nss_base_shadow dc=example,dc=com
nss_base_group dc=example,dc=com
nss_map_objectclass posixAccount user
nss_map_objectclass shadowAccount user
nss_map_objectclass posixGroup group
nss_map_attribute uid sAMAccountName
nss_map_attribute uidNumber msSFU30UidNumber
nss_map_attribute gidNumber msSFU30GidNumber
nss_map_attribute loginShell msSFU30LoginShell
nss_map_attribute gecos name
nss_map_attribute userPassword msSFU30Password
nss_map_attribute homeDirectory msSFU30HomeDirectory
nss_map_attribute uniqueMember msSFU30PosixMember
nss_map_attribute cn cn - Securely copy the file created using the ktpass.exe utility above to the Linux server in question, placing it in the /etc directory as krb5.keytab. (SFTP or SCP are excellent candidates for this.)
- Configure PAM (this varies according to Linux distributions) to use pam_krb5 for authentication. Many modern distributions use a stacking mechanism whereby one file can be modified and those changes will applied to all the various PAM-aware services. For example, in Red Hat-based distributions, the system-auth file is referenced by most other PAM-aware services.
- Edit the /etc/nsswitch.conf file to include “ldap†as a lookup source for passwd, shadow, and groups.
That should be it. Once you do that, you should be able to use kinit from a Linux shell prompt (for example, “kinit aduserâ€) and generate a valid Kerberos ticket for the specified Active Directory account.
At this point, any PAM-aware service that is configured to use the stacked system file (such as the system-auth configuration on Red Hat-based distributions) will use Active Directory for authentication. Note, however, that unless you also add the pam_mkhomedir.so module in the PAM configuration, home directories will have to be created manually for any Active Directory account that may log on to that server. (I generally recommend the use of pam_mkhomedir.so in this situation.)
Tags: ActiveDirectory, Kerberos, LDAP, Linux, Microsoft, OSS, Windows


16 comments
Comments feed for this article
Trackback link
http://blog.scottlowe.org/2005/12/22/complete-linux-ad-authentication-details/trackback/
Wednesday, August 20, 2008 at 4:14 am
Pingback from Linux-AD Integration, Version 4 « Junji’s Blog Site
Tuesday, December 12, 2006 at 1:04 am
Matt
I was able to get ssh authenticating against AD, thanks for the docs.
Have you been able to setup multiple AD security groups so that depending on what group you are in it will determine what servers you can log into. ie. developers can only log into a couple servers, sysadmins can log into all servers.
Also, are you using sudo to limit what those groups can do once logged in?
Tuesday, December 12, 2006 at 8:58 am
slowe
Matt,
I’m glad you found the information helpful.
With regards to your questions, I wrote an article on the use of security groups for access control. You can read that article here:
http://blog.scottlowe.org/2006/09/08/ldap-based-access-control/
I have not yet gotten a configuration for using sudo to limit what those groups can do. However, I suspect that it would be as simple as configuring the /etc/sudoers file with the names of the users/groups (as defined in Active Directory) and going from there. Unless I misunderstand your question?
Scott
Friday, January 12, 2007 at 6:48 pm
MarkW
Scott, your posts have been _really_ helpful. Is it me or are the MS docs full of smoke and mirrors just like the OS?
I wanted to post to let you know that I found a quick and dirty way to test this stuff without installing SFU (something that could take a while to get done in large enterprise environments.
Basically, there are some ‘extensionAttributes’ in AD that you can use to populate the required information needed for a login. You can map the standard attribute names in ldap.conf something like this:
nss_map_attribute uidNumber extensionAttribute1
nss_map_attribute gidNumber extensionAttribute2
nss_map_attribute homeDirectory extensionAttribute3
nss_map_attribute loginShell extensionAttribute4
These attributes can be found in the Exchange Advanced tab. There will be some workable problems (group resolution) but the basic authentication will work.
Mark
Friday, January 12, 2007 at 8:12 pm
slowe
Mark,
I think I’ll pass on commenting about the MS docs or their operating system….but otherwise that’s a great suggestion. I should have thought of that. Thanks for sharing it with us.
Scott
Friday, February 23, 2007 at 3:35 pm
Noop
Hi,
Just out of curiosity. I haven’t set this up yet. I was reading other sources of information as well but what is the login format when logging in over SSH or at the console?
DOMAINNAME\Username
or just
Username
Thanks much. Great article!
Friday, February 23, 2007 at 10:07 pm
slowe
Good question! You’ll log in with just the username.
Scott
Monday, March 26, 2007 at 1:20 pm
chris dolese
does anyone have specifics on what options should be taken and how for the install of of microsoft SFU 3.5
Monday, March 26, 2007 at 9:25 pm
chris dolese
keytab file creation …
i wound up having to use whats below :
ktpass -princ host/mylinuxserver.mydomain.com@LANDAIR -mapuser MYDOMAIN\mylinuxserver$ -crypto DES-CBC-MD5 -pass mypassword -ptype KRB5_NT_PRINCIPAL -out mykeytabfilename
Tuesday, March 27, 2007 at 10:30 am
slowe
Chris,
I believe you’ll need the Server for NIS component (this actually installs the schema extensions and the add-in for Active Directory Users and Computers), but I think most of the rest of it is not needed. However, it’s been a while since I did this. Do you have access to Windows Server 2003 R2? It includes SFU 3.5 and uses a newer (and, in my opinion, more compatible) set of schema extensions for UNIX attributes.
Wednesday, November 14, 2007 at 5:22 pm
Alex
Trying to follow this, but having a hell of a time with Kerberos. I follow the directions here and get the following Warning/Error
WARNING: Account DEVSERVER$ is not a user account (uacflags=0×1021).
WARNING: Resetting DEVSERVER$’s password may cause authentication problems if DEVSERVER$ is being used as a server.
Reset DEVSERVER$’s password [y/n]? y
WARNING: pType and account type do not match. This might cause problems.
I then copy the resulting keytab file to the server and try:
kinit -V -k -t ./devserver.keytab host/devserver.dsgi.us
and get the following message:
kinit(v5): Key table entry not found while getting initial credentials
Any idea what I am doing wrong?
Thursday, March 13, 2008 at 5:53 pm
Ryan
Hi,
Just a shot in the dark to hopefully get a response. I realize this article is a bit old.
Anyways, I’ve been working on Red Hat/AD authentication for a little while now and I managed to get my Red Hat version AS4 authenticating to the AD server just fine. However, when I follow the exact same steps on a Red Hat ES3 server, it doesn’t work.
Kerberos configures properly (I can generate tickets for AD users no problem) but cannot logon or anything else.
I tried making my ldap.conf file the same as yours (adding a few attributes) but still nothing. I also read you mention there are differences between Red hat versions regarding system-auth. Both my files are word for word identical.
Is there something I should be doing differently for ES3 and AS4?
Thanks,
Ryan
Tuesday, July 1, 2008 at 12:34 pm
Greg Kenoyer
Ryan, While you may never come back to this page I thought I should just answer for future readers. I am also on this path and am trying to tie my AD to RHEL v5.1/2 workstations.
I encountered the same issue (able to generate tickets but cannot logon). I was able to finally log on when I created (via adduser script) a local account that matched the AD account. I am still trying to get the username map and the winbind methods to work…but at least I know that the other ’stuff’ is working.
Tuesday, July 1, 2008 at 5:48 pm
slowe
Greg,
Great point–adding a local user is a great way to help isolate some of the different components involved in this kind of integration project. This at least lets you determine if the problem is Kerberos, LDAP, PAM, or something else entirely.
Thanks for reading!
Tuesday, July 15, 2008 at 2:51 pm
User
I have followed the instructions as above but without using SFU as post 3. However getent passwd username returns nothing. /etc/ldap.conf looks correct.
Can you help?
Saturday, July 26, 2008 at 12:33 am
Deependra Singh Shekhawat
Hi,
Very excellent tutorial. I was able to authenticate Linux machines from Active Directory on windows server 2003.
Kerberos part really helped me alot.
Will be reading your article regarding NFS mounts next.
Again thanks alot.