Install And Configure OpenLDAP In Ubuntu 15.04 And Debian 8
About OpenLDAP
OpenLDAP is a free open source Light Weight Directory Access protocol developed by the OpenLDAP project. It is a platform independent protocol, so that it runs on all Linux/Unix like systems, Windows, AIX, Solaris and Android.
OpenLDAP includes:
- slapd – stand-alone LDAP daemon (server)
- libraries implementing the LDAP protocol, and
- utilities, tools, and sample clients.
In this tutorial, let us see how to install and configure OpenLDAP in Ubuntu / Debian server. Due to lack of resources and time, I tested this how-to only in Ubuntu 15.04. However, the following steps should work on Debian 7/8 and previous versions of Ubuntu, including Ubuntu 14.10/14.04/13.10/13.04/12.10 etc. If you had any issues while installing OpenLDAP in other distros, feel free to let me know, I will check and update this how-to ASAP.
Well, let us begin to setup LDAP server.
Here is my LDAP server’s details:
Operating System : Ubuntu 15.04 Hostname : server.unixmen.local IP Address : 192.168.1.100
Replace the above values with your own.
Install And Configure OpenLDAP
First let us see how to install OpenLDAP in DEB based systems.
1. Install OpenLDAP
Enter the following command in Terminal to install openldap.
Switch to root user:
sudo su
Or
su
Run the following command to install OpenLDAP.
apt-get install slapd ldap-utils
During the installation, you’ll be asked to set password for the LDAP admin account. Enter your admin password here.
Re-enter the password.
OpenLDAP is installed now. Let’s go to the configuration task.
2. Configure OpenLDAP
Edit “/etc/ldap/ldap.conf” file,
vi /etc/ldap/ldap.conf
Find, uncomment and replace ‘BASE’ and ‘ URI’ values with your domain name and IP Address as shown below.
# # LDAP Defaults # # See ldap.conf(5) for details # This file should be world readable but not world writable. BASE dc=unixmen,dc=local URI ldap://server.unixmen.local ldap://server.unixmen.local:666 #SIZELIMIT 12 #TIMELIMIT 15 #DEREF never # TLS certificates (needed for GnuTLS) TLS_CACERT /etc/ssl/certs/ca-certificates.crt
Save and close the file.
Next, we should reconfigure the slapd with the updated values.
dpkg-reconfigure slapd
The following screen should appear. Select “No” and press Enter.
Enter the DNS domain name.
Enter the Organization name (i.e your company name).
Enter the LDAP admin password which you created in the earlier step.
Re-enter the password.
Select the backend database. I go with defaults.
Select whether you want to delete the database automatically or keep it when slapd is removed. Here i want to keep my old database, hence i clicked No.
Select Yes to move old database.
Select No and Press Enter.
That’s it. We have successfully configured OpenLDAP. Let us go ahead and check whether it’s working or not.
Test LDAP Server
Run the following command to test OpenLDAP:
ldapsearch -x
Sample output:
# extended LDIF # # LDAPv3 # base <dc=unixmen,dc=local> (default) with scope subtree # filter: (objectclass=*) # requesting: ALL # # unixmen.local dn: dc=unixmen,dc=local objectClass: top objectClass: dcObject objectClass: organization o: unixmen dc: unixmen # admin, unixmen.local dn: cn=admin,dc=unixmen,dc=local objectClass: simpleSecurityObject objectClass: organizationalRole cn: admin description: LDAP administrator # search result search: 2 result: 0 Success # numResponses: 3 # numEntries: 2
If you see the ‘Success’ message in your output, then Congratulations! LDAP Server is working!!
LDAP Server Administration
Administration of LDAP server in command mode is bit difficult. We can’t remember all LDAP commands. So, we will use an easier GUI administration tool called “phpldapadmin” to manage, configure, and administer LDAP server.
Install phpLDAPadmin
phpLDAPadmin is a web-based LDAP administration tool for managing your LDAP server. Using phpLDAPadmin, you can browse your LDAP tree, view LDAP schema, perform searches, create, delete, copy and edit LDAP entries. You can even copy entries between servers.
Enter the following command to install phpLDAPAdmin:
apt-get install phpldapadmin
Create a symbolic link for phpldapadmin directory.
ln -s /usr/share/phpldapadmin/ /var/www/html/phpldapadmin
On Ubuntu 14.10 and lower versions, run:
ln -s /usr/share/phpldapadmin/ /var/www/phpldapadmin
Edit “/etc/phpldapadmin/config.php” file,
vi /etc/phpldapadmin/config.php
Set the correct timezone. To do that, find and uncomment the following line and set your Timezone.
[...] $config->custom->appearance['timezone'] = 'Asia/Kolkata'; [....]
Scroll down further and Replace the domain names with your own values.
To do that, Find “Define LDAP Servers” section in the config file and edit the following lines as shown below.
[...] // Set your LDAP server name // $servers->setValue('server','name','Unixmen LDAP Server'); [...] // Set your LDAP server IP address // $servers->setValue('server','host','192.168.1.100'); [...] // Set Server domain name // $servers->setValue('server','base',array('dc=unixmen,dc=local')); [...] // Set Server domain name again// $servers->setValue('login','bind_id','cn=admin,dc=unixmen,dc=local'); [...]
Restart the apache service.
systemctl restart apache2
On Ubuntu 14.10 and older versions, run:
service apache2 restart
Make sure that you have opened apache server port “80” and LDAP default port “389” in your firewall/router configuration.
ufw allow 80
Sample output:
Rules updated Rules updated (v6)
ufw allow 389
Sample output:
Rules updated Rules updated (v6)
The above steps are not necessary for Debian systems.
Test phpLDAPadmin
Open your web browser and navigate to: “http://192.168.1.100/phpldapadmin”.
The following screen should appear.
Click “login” on the left pane. Enter the LDAP admin password that you have created during OpenLDAP installation, and click “Authenticate”.
Now the main console screen of phpldapadmin will open.
You can see the LDAP domain “unixmen.local” and other details on the left.
From here, you can add additional objects, such as Organizational Unit, Users and groups etc.
Creating Objects
1. Create Organizational Unit(OU):
Lets create some sample objects from the phpldapadmin console. First, we will create an OU.
Click on the “+” sign near the line “dc=unixmen” and click “Create new entry here” link.
Scroll down and Select “Generic-Organizational Unit”.
Enter the name of the Organizational unit (Ex.sales) and Click “Create Object”.
Finally, click “Commit”.
You can find the newly created OU in main LDAP section on the left.
2. Create Group:
Click on the sales OU on the left pane and click on “Create a child entry” link.
In the next window, Select “Generic: Posix Group”.
Enter the name of the group and click Create Object button. For example, here i enter the group name as “sales-group”.
Click Commit to save changes.
Now you can see that the newly created group called “sales-group” under the sales OU.
3. Create User:
Now, let us create a new user under sales-group.
Click on the sales-group on the left.
Select Create a child entry link button.
In the next window, Select “Generic: User Account”.
Enter the user details such as common name, GID number, last name, Login shell, user password and user id etc., as shown in the below screen shot and click Create object. For example. here I am going to create a user called“kumar”.
And then Click “Commit” to save the changes.
Now the newly created user “kumar” will be found under “sales-group” object.
Also, you can verify the newly created objects are really existing with command:
ldapsearch -x
Sample output:
# extended LDIF # # LDAPv3 # base <dc=unixmen,dc=local> (default) with scope subtree # filter: (objectclass=*) # requesting: ALL # # unixmen.local dn: dc=unixmen,dc=local objectClass: top objectClass: dcObject objectClass: organization o: unixmen dc: unixmen # admin, unixmen.local dn: cn=admin,dc=unixmen,dc=local objectClass: simpleSecurityObject objectClass: organizationalRole cn: admin description: LDAP administrator # sales, unixmen.local dn: ou=sales,dc=unixmen,dc=local objectClass: organizationalUnit objectClass: top ou: sales # sales-group, sales, unixmen.local dn: cn=sales-group,ou=sales,dc=unixmen,dc=local gidNumber: 500 cn: sales-group objectClass: posixGroup objectClass: top # kumar, sales-group, sales, unixmen.local dn: cn=kumar,cn=sales-group,ou=sales,dc=unixmen,dc=local cn:: IGt1bWFy gidNumber: 500 homeDirectory: /home/users/kumar sn: kumar loginShell: /bin/sh objectClass: inetOrgPerson objectClass: posixAccount objectClass: top uidNumber: 1000 uid: kumar # search result search: 2 result: 0 Success # numResponses: 6 # numEntries: 5
As you see in the above output, the new objects, namely ‘sales’, ‘sales-group’, and ‘kumar’ has been successfully created under the main LDAP domain. Similarly, you can create as many as objects you wanted.
Installing and configuring OpenLDAP in Debian and Ubuntu and derivatives is really easy and fun. Even a novice users can easily setup a working LDAP server within an hour.
Now OpenLDAP Server is ready to use.
Good luck!
=========================================================
Configure Linux Clients To Authenticate Using OpenLDAP
In this guide let us see how to configure Linux clients to authenticate using OpenLDAPserver. I have tested this Guide on Debian 8 desktop and Ubuntu 15.04 desktop, it worked perfectly without any issues. And also, this guide should on other Debian and Ubuntu distributions. If you find any problems, feel free to let me know. I will check and update this tutorial ASAP.
For the purpose of this tutorial, we will be using Debian 8 MATE desktop as LDAP client.
My client system’s details:
- Operating system: Debian 8 MATE desktop
- IP Address: 192.168.1.150/24
My LDAP Server’s details:
- Operating system: Ubuntu 15.04 server
- IP Address: 192.168.1.100/24
Configure Linux Clients To Authenticate Using OpenLDAP
Here, I am going to split this tutorial into two sections. First, we’ll see how to install LDAP client on Debian 8, and then we’ll see how to configure Debian 8 desktop to authenticate.
1. Install LDAP client
I assume that you’ve had a working LDAP server already. If not, refer the above link to setup OpenLDAP server in Debian and Ubuntu and its derivatives.
Now let us install the required packages in our LDAP client.
Switch to root user:
sudo su
Or
su
Run the following command from your Terminal to install LDAP client packages.
apt-get install libnss-ldap libpam-ldap nscd
During installation, you will be asked a variety of questions. Read them carefully and enter the appropriate values.
First enter the ldap server IP address as shown in the below screenshot.
Note that you should enter LDAP server URI as ldap://ip-address-of-ldapserver/. Using IP address is always recommended to avoid failures when domain name services are unavailable.
Then enter the distinguished name of the search base. This value should match with your LDAP server’s/etc/phpldaadmin/config.php file values. In my case it’s dc=unixmen, dc=local.
Select Ldap version to use as 3. It is recommended to use highest available version.
Enter LDAP administrative account details.
In our case, it was: cn=admin, dc=unixmen.com, dc=local.
Enter LDAP administrative password:
The next window will say that you have to manually edit nsswitch.conf file. Click Ok to continue.
Now the libnss-ldap package has been installed. Now, we should enter the same answers for libpam-ldap, i.e the above questions will be repeated for libpam-ldap.
We don’t need to act the client LDAP admin account as local root, hence we will select No.
Select No.
Now, let us reconfigure libnss-ldap to improve debconf configuration by entering the following command:
dpkg-reconfigure libnss-ldap
Make sure that the LDAP server URI is correct.
Make sure that the LDAP server search base:
LDAP version to use:
LDAP database doesn’t require login, hence we select No.
Select No.
Select No.
Finally, Select Ok.
That’s it. Now we have installed ldap client packages.
2. Configure LDAP Client
We must update our client system to look for LDAP server by adjusting their configuration files.
To do so, First edit file /etc/ldap/ldap.conf,
nano /etc/ldap/ldap.conf
Uncomment the following lines and Enter your LDAP server search BASE and URI as shown below.
[...] BASE dc=unixmen,dc=local URI ldap://192.168.1.100 [...]
Edit file /etc/nsswitch.conf,
nano /etc/nsswitch.conf
Find the following three lines and adjust them as shown below.
[...] passwd: compat ldap group: compat ldap shadow: compat ldap [...] netgroup: ldap [...]
Now restart nscd service:
systemctl restart nscd
On Ubuntu 14.10/Debian 7 and previous versions:
service nscd restart
PAM Configuration
Now we should verify the PAM configuration. The PAM configuration is modified during libnss-ldap installation. But it is advisable to verify the PAM configuration files as look like below.
Edit file /etc/pam.d/common-auth,
nano /etc/pam.d/common-auth
Make sure this file contains the following lines.
[...] auth [success=2 default=ignore] pam_unix.so nullok_secure try_first_pass auth [success=1 default=ignore] pam_ldap.so use_first_pass [...] auth requisite pam_deny.so [...] auth required pam_permit.so [...]
Edit file /etc/pam.d/common-account,
nano /etc/pam.d/common-account
[...] account [success=2 new_authtok_reqd=done default=ignore] pam_unix.so account [success=1 default=ignore] pam_ldap.so [...] account requisite pam_deny.so [...] account required pam_permit.so [...]
Edit file nano /etc/pam.d/common-password,
nano /etc/pam.d/common-password
[...] password [success=2 default=ignore] pam_unix.so obscure sha512 password [success=1 user_unknown=ignore default=die] pam_ldap.so use_authtok try_first_pass [...] password requisite pam_deny.so [...] password required pam_permit.so [...]
Edit file /etc/pam.d/common-session,
nano /etc/pam.d/common-session
Add the following line at the bottom.
[...]
session required pam_mkhomedir.so
The above line will create a HOME directory for LDAP users who does not have home directory when login to LDAP server.
Edit file /etc/pam.d/common-session-noninteractive,
nano /etc/pam.d/common-session-noninteractive
[...] session [default=1] pam_permit.so [...] session requisite pam_deny.so [...] session required pam_permit.so [...] session required pam_unix.so session optional pam_ldap.so
Restart nscd service to save changes.
systemctl restart nscd
On Debian 7/Ubuntu 14.10 and lower versions:
service nscd restart
Reboot your client system and try to login with your LDAP user from client system.
Log In To LDAP Server
Now, we have configured our client to be able to log in to our OpenLDAP server. Let us try to login using any ldap users created in the openldap server. Please note that this LDAP user doesn’t exist in the local client system. Don’t be confused.
I have already created a user named “kumar” in my OpenLDAP server. Refer the section Sample Configurationin my previous tutorial.
So, now let us login with user “kumar”.
Enter your LDAP user name and password.
Please note that the user named “kumar” is not a local user. We have created this user in our previous guide using phpLDAPAdmin tool..
Congratulations! Now, you will be able to log in to your client system with LDAP user.
Let us check who exactly is this user.
Open Terminal, and run:
whoami
Sample output:
kumar
Run pwd command from the Terminal to know the user’s present working directory:
pwd
Sample output:
/home/users/kumar
You should see that the home directory you selected for your user on the LDAP server is being used on this machine. It has been created on-demand to serve the LDAP user.
You should now be able to authenticate multiple computers using a centralized LDAP server. Your LDAP users will be allowed to use any of the machines you configure in this way, as long as they have the valid login credentials.
Initially this how-to will look bit difficult, but if you follow the steps carefully you will be able to setup the complete LDAP server/client.
Good Luck!
Reference: Setup OpenLDAP On Debian
No comments:
Post a Comment