LDAP Authentication In Linux
LDAP Authentication In LinuxThis howto will show you howto store your users in LDAP and authenticate some of the services against it. I will not show howto install particular packages, as it is distribution/system dependant. I will focus on "pure" configuration of all componenets needed to have LDAP authentication/storage of users. The howto assumes somehow, that you are migrating from a regular passwd/shadow authentication, but it is also suitable for people who do it from scratch. RequirementsIntroducionThe thing we want to achieve is to have our users stored in LDAP, authenticated against LDAP ( direct or pam ) and have some tool to manage this in a human understandable way. This way we can use all software, which has ldap support or fallback to PAM ldap module, which will act as a PAM->LDAP gateway. More information on LDAP idea can be found on Wikipedia: LDAP wikipedia Configuring OpenLDAPOpenLDAP consists of slapd and slurpd daemon. This howto covers one LDAP server without a replication, so we will focus only on slapd. I also assume you installed and initialized your openldap installation (depends on system/disribution). If so, let's go to configuration part. On my system (Gentoo), openldap's configuration is stored in /etc/openldap, we are interested in /etc/openldap/slapd.conf file. But first we have to generate a password for LDAP administrator, to put it into the config file: slappasswd -h {md5} The config looks like this:include /etc/openldap/schema/core.schema Remember to change suffix and paths to your needs. These are basic options with some basic ACLs needed to change passwrods by user. If you want more functionality, please read the manual about openLDAP. Now when we have a proper config for slapd, we can start the daemon : /etc/init.d/slapd start Please remember to have something like that in the config file responsible for arguments passed to the slapd (the path should point to the slapd.sock): OPTS="-h 'ldaps:// ldapi://%2fvar%2frun%2fopenldap%2fslapd.sock'" Now we can test if openldap is running and working properly. We do not have any data yet in the directory, but we can try to bind as cn=Manager,dc=domain,dc=com. When you are asked for password, you should use the one you generated (of course the plain text version of it :): ldapsearch -D "cn=Manager,dc=domain,dc=com" -W Migrate/Add data to the directoryNow when we have a running LDAP server, we have to fill it with data, either create or migrate entries. I will show you howto migrate existing entries from regular /etc/passwd, /etc/shadow , /etc/groups The first step is to configure mogrationtools to your needs. The configuration file on gentoo is located in /usr/share/migrationtools/migrate_common.ph. Generally you need to change only these:$DEFAULT_BASE = "dc=domain,dc=com"; Now you are ready to migrate the data (actually it works even without the export command):
export ETC_SHADOW=/etc/shadow Now we have the data in the format understood by LDAP server. Please open one the files with text editor to get used to the syntax. After that we can add the data from ldifs. ldapadd -D "cn=Manager,dc=domain,dc=com" -W -f /tmp/base.ldif ldapadd -D "cn=Manager,dc=domain,dc=com" -W -f /tmp/group.ldif ldapadd -D "cn=Manager,dc=domain,dc=com" -W -f /tmp/passwd.ldif ldapadd -D "cn=Manager,dc=domain,dc=com" -W -f /tmp/hosts.ldif You can try searching for some data: ldapsearch uid=foouser Client configurationBy client I mean the machine, which connects to LDAP server to get users and authorize. It can be also the machine, the ldap server runs on. In both cases we have to edit three files : /etc/ldap.conf, /etc/nsswitch.conf and /etc/pam.d/system-auth Let's start woth ldap.conf, the ldap's client: BASE dc=domain, dc=com Now it is time for nsswitch.conf and pam Add these to nsswitch.conf:passwd: files ldapAnd change the system-auth (or hatever you have like login, sshd etc) to : auth required pam_env.so Time to test it. The best tool for it is a good old getent. Pick a user from your system and issue: getent passwd | grep foouser You should get the result twice, if so the nss_ldap works fine. The pam part can be tested by deleting a user from the /etc/passwd and trying to log in through ssh. Apache mod_auth_ldapTo have LDAP authorization in apache, you have to load mod_auth_ldap module LoadModule mm_auth_ldap_module modules/mod_auth_ldap.so Now it is enought to make .htaccess like that: AuthName "Restricted" Note that this method can be also used for webdav subversion authorization Administration tools for ldapThere are few tool I recommend using to administrate OpenLDAP server
Other ldap aware applications
SummaryIf someone has something to add, please do it. I know the configuration may not be perfect.
|



![Creative Commons Attribution License [Creative Commons Attribution License]](http://creativecommons.org/images/public/somerights20.gif)




Recent comments
1 day 7 hours ago
1 day 12 hours ago
3 days 8 hours ago
5 days 5 hours ago
6 days 7 hours ago
6 days 19 hours ago
1 week 10 hours ago
1 week 20 hours ago
1 week 1 day ago
1 week 1 day ago