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
-
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?
-
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 extensionAttribute4These attributes can be found in the Exchange Advanced tab. There will be some workable problems (group resolution) but the basic authentication will work.
Mark
-
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!
-
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.usand get the following message:
kinit(v5): Key table entry not found while getting initial credentialsAny idea what I am doing wrong?
-
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 -
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. -
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?
-
I’m about to add 200 linux users to my domain and thought about the option you offer but I was worried about the overhead of ldap server.
I ran into this article and thought using it through winbind
http://technet.microsoft.com/en-us/magazine/2008.12.linux.aspxDoes single sign on really work for you with the method that you described?
-
Slowe,
forgot to mention that I have 2008 AD installed, I’m going to test your method with ubuntu clients. I saw your article about the 2008 server so I’ll use that and will let you know if i have any issues.




19 comments
Comments feed for this article
Trackback link: http://blog.scottlowe.org/2005/12/22/complete-linux-ad-authentication-details/trackback/