Ubuntu: LDAP – Install, Configure & Test
I’m using Ubuntu 12.04
LDAP: Install & Configure
sudo apt-get install slapd ldap-utils
- Enter password: [SetY0urP@$$wOrD]
dpkg-reconfigure slapd
- Omit OpenLDAP server configuration? No
- DNS domain name? domain.com | IP Address
- Organization name? My Organization
- Administrator password? Use the password during installation | Choose new one
- Database backend to use? HDB
- Remove the database when slapd is purged? No
- Move old database? Yes
- Allow LDAPv2 protocol? No
- joe /etc/phpldapadmin/config.php (i’m using joe text editor, you may use the default text editor such vi)
$servers->setValue('server','host','domain.com | IP Address'); $servers->setValue('server','base',array('dc=domain,dc=com')); $servers->setValue('login','bind_id','cn=admin,dc=domain,dc=com'); $config->custom->appearance['hide_template_warning'] = true;
LDAP: Install PHPLDAPAdmin
apt-get install libpam-ldap nscd | pkg-reconfigure ldap-auth-config
- LDAP server Uniform Resource Identifier: ldap://**Domain-Name-OR-IP-Address** ( Change the initial string from “ldapi:///” to “ldap://” before inputing your server’s information )
- Distinguished name of the search base: ( This should match the value you put in your LDAP server’s
/etc/phpldapadmin/config.php
file. ) - LDAP version to use: 3
- Make local root Database admin: Yes
- Does the LDAP database require login? No
- LDAP account for root: This should also match the value in your
/etc/phpldapadmin/config.php
- LDAP root account password: LDAP-Root-Password
joe /etc/nsswitch.conf
– addldap
beforecompat
for each passwd, group, shadowjoe /etc/pam.d/common-session
– add at the bottom:session required pam_mkhomedir.so skel=/etc/skel umask=0022
/etc/init.d/nscd restart
- Access to PHPLDAPAdmin: http://domain.com/phpldapadmin
LDAP: Setting up LDAP Groups & Users
- Go to http://domain.com/phpldapadmin
- Login DN:
cn=admin,dc=domain,dc=com
- Login Password: Password configured during
slapd
configuration - To do:
- Create an Generic: Organization Units named Users
- Create a Generic: Posix Group named groups
- Create one or more Generic: User Account (make sure it’s under ou=users)
- (Optional) Add users to groups by clicking a group & Add New Attribute. Select memberUid and click on Update Object at the bottom.
LDAP: Test LDAP
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); $ldapconn = ldap_connect("domain.com") or die("Could not connect to LDAP server."); $person = 'cn=username,ou=users,dc=domain,dc=com'; $password = 'password'; if ($ldapconn) { $ldapbind = ldap_bind($ldapconn, $person, $password); if ($ldapbind) { $ldaptree = "ou=users,dc=domain,dc=com"; $justthese = array("ou", "sn", "givenname"); $result = ldap_search($ldapconn,$ldaptree,"givenName=$person",$justthese) or die ("Error in search query: ".ldap_error($ldapconn)); $no = ldap_count_entries($ldapconn, $result); echo 'Count Entries: ' . $no . '<br>'; $info = ldap_get_entries($ldapconn, $result); for ($i=0; $i<$info["count"]; $i++) { echo $info[$i]['givenname'][0] . ' (' . $info[$i]['mail'][0] . ')'; echo '<hr>'; } } else { echo "LDAP bind ".$user." failed..."; } }
Reference: Installing LDAP on Ubuntu 12.04
There’s definately a great deal to know about this
topic. I really like all of the points you have made.