LDAP stands for Lightweight Directory Access Protocol.
LDAP is a solution to access centrally stored information over network. This centrally stored information is organized in a directory that follows X.500 standard.
The information is stored and organized in a hierarchical manner and the advantage of this approach is that the information can be grouped into containers and clients can access these containers whenever needed.
The OpenLDAP hierarchy is almost similar to the DNS hierarchy.
The following are the two most commonly used objects in OpenLDAP:
- cn (common name) – This refers to the leaf entries, which are end objects (for example: users and groups)
- dc (domain component) – This refers to one of the container entries in the LDAP hierarchy. If in a setup the LDAP hierarchy is mapped to a DNS hierarchy, typically all DNS domains are referred to as DC objects.
For example, if there is user in the hierarchy sam.thegeekstuff.com, the fully distinguished name of this user is referred as cn=sam, dc=thegeekstuff, dc=com. If you noticed in the FDN (fully distinguished name), a comma is used a separator and not a dot, which is common in DNS.
By using the different LDAP entry types, you can setup a hierarchical directory structure. This is the reason why openLDAP is so widely used. You can easily build an openLDAP hierarchy where objects in the other locations are easily referred to without storing them on local servers. This makes OpenLDAP a lightweight directory, especially when compared to other directory servers such as Microsoftβs Active directory.
Now lets see how to setup a single instance of an LDAP server that can be used by multiple clients in your network for authentication.
Install OpenLDAP Packages
On CentOS and RedHat, use yum install as shown below, to install the openldap related packages.
yum install -y openldap openldap-clients openldap-servers
You should install the following three packages:
- openldap-servers – This is the main LDAP server
- openldap-clients – This contains all required LDAP client utilities
- openldap – This packages contains the LDAP support libraries
LDAP Config Files
- config.ldif – The LDAP default configuration is stored under a file in /etc/openldap/slapd.d/cn=config.ldif that is created in the LDIF format. This is the LDAP Input Format (LDIF), a specific format that allows you to enter information in to the LDAP directory.
- olcDatabase{2}bdb.ldif – You can also modify the settings like number of connections the server can support, timeouts and other database settings under the file /etc/openldap/slapd.d/cn=config/olcDatabase{2}bdb.ldif. This is the file that also contains the parameters like LDAP root user and the base DN.
Create olcRootDN Account as Admin
It is always recommended to create a dedicated user account first with the full permissions to change information on the LDAP database.
Modify the olcDatabase={2}bdb.ldif file, and change the olcRootDN entry. The following is the default entry.
# grep olcRootDN /etc/openldap/slapd.d/cn=config/olcDatabase={2}bdb.ldif olcRootDN: cn=Manager,dc=my-domain,dc=com
Change the above line to an admin user. In this example, user “ramesh” will be the olcRootDN.
olcRootDN: cn=ramesh,dc=thegeekstuff,dc=com
Create olcRootPW Root Password
Now use slappasswd command to create a hash for the root password you want to use. Once the password is generated, open the cn=config.ldif file, include the olcRootPW parameter, and copy the hashed password as shown below.
Execute the following command and specify a password. This will generate the hash for the given password.
# slappasswd New password: SecretLDAPRootPass2015 Re-enter new password: SecretLDAPRootPass2015 {SSHA}1pgok6qWn24lpBkVreTDboTr81rg4QC6
Take the hash output of the above command and add it to the oclRootPW parameter in the config.ldif file as shown below.
# vi /etc/openldap/slapd.d/cn=config.ldif olcRootPW: {SSHA}1pgok6qWn24lpBkVreTDboTr81rg4QC6
Create olcSuffix Domain Name
Now setup the olcSuffix and to set the domain that you want. Simply modify the line that starts with olcSuffix in the file olcDatabase={2}bdb.ldif as shown below.
# vi /etc/openldap/slapd.d/cn=config/olcDatabase={2}bdb.ldif olcSuffix: dc=thegeekstuff,dc=com
Verify The Configuration Files
Use slaptest command to verify the configuration file as shown below. This should display “testing succeeded” message as shown below.
# slaptest -u config file testing succeeded
You might get the following messages during the above command, which you can ignore for now.
54a39508 ldif_read_file: checksum error on "/etc/openldap/slapd.d/cn=config/olcDatabase={1}monitor.ldif" 54a39508 ldif_read_file: checksum error on "/etc/openldap/slapd.d/cn=config/olcDatabase={2}bdb.ldif"
Start the LDAP Server
Start the ldap server as shown below.
# service slapd start Checking configuration files for slapd: [WARNING] config file testing succeeded Starting slapd: [ OK ]
Verify the LDAP Search
To verify the ldap server is configured successfully, you can use the below command and verify that the domain entry is present.
# ldapsearch -x -b "dc=thegeekstuff,dc=com" # extended LDIF # # LDAPv3 # base <dc=thegeekstuff,dc=com> with scope subtree # filter: (objectclass=*) # requesting: ALL # # search result search: 2 result: 32 No such object # numResponses: 1
Base LDAP Structure in base.ldif
The use of OU (organizational unit) objects can help you in providing additional structure to the LDAP database. If you are planning on adding in different types of entries, such as users, groups, computers, printers and more to the LDAP directory, it makes it easier to put every entry type into its own container.
To create these OU’s, you can create an initial LDIF file as shown in the below example. In this example, this file allows you to create the base container which is dc=thegeekstuff,dc=com and it creates two organizational units with the names users and groups in that container.
# cat base.ldif dn: dc=thegeekstuff,dc=com objectClass: dcObject objectClass: organization o: thegeekstuff.com dc: thegeekstuff dn: ou=users,dc=thegeekstuff,dc=com objectClass: organizationalUnit objectClass: top ou: users dn: ou=groups,dc=thegeekstuff,dc=com objectClass: organizationalUnit objectClass: top ou: groups
Import Base Structure Using ldapadd
Now we can import the base structure in to the LDAP directory using the ldapadd command as shown below.
# ldapadd -x -W -D "cn=ramesh,dc=thegeekstuff,dc=com" -f base.ldif Enter LDAP Password: adding new entry "dc=thegeekstuff,dc=com" adding new entry "ou=users,dc=thegeekstuff,dc=com" adding new entry "ou=groups,dc=thegeekstuff,dc=com"
Verify the Base Structure using ldapsearch
To verify the OUs are successfully created, use the following ldapsearch command.
# ldapsearch -x -W -D "cn=ramesh,dc=thegeekstuff,dc=com" -b "dc=thegeekstuff,dc=com" "(objectclass=*)" Enter LDAP Password:
The output of the above command will display all the objects in the LDAP directory structure.
# extended LDIF # # LDAPv3 # base <dc=thegeekstuff,dc=com> with scope subtree # filter: (objectclass=*) # requesting: ALL # # thegeekstuff.com dn: dc=thegeekstuff,dc=com objectClass: dcObject objectClass: organization o: thegeekstuff.com dc: thegeekstuff # users, thegeekstuff.com dn: ou=users,dc=thegeekstuff,dc=com objectClass: organizationalUnit objectClass: top ou: users # groups, thegeekstuff.com dn: ou=groups,dc=thegeekstuff,dc=com objectClass: organizationalUnit objectClass: top ou: groups # search result search: 2 result: 0 Success # numResponses: 4 # numEntries: 3
In the next OpenLDAP article, we’ll explain how to add new users and groups to the LDAP Directory.
Comments on this entry are closed.
Hi,
Thanks a lot for very nice article.
How to create a group called testgroup and a user (testuser1) where testuser1 belongs to only testgroup.
Great, thanks for very nice article. Please post next article soon. π
The problem with this kind of how-to is that its too general and not actually useful.
What I’d want to see is, for example, how to set up LDAP to support my database of contacts supporting both my Thunderbird on PC and on my tablet and phone emailers. And that database is not of “internal, corporate” but of all the different classes of contacts, for example, Iβm currently managing under Thunderbird.
Good article thanks, do you think that you could cover how to implement TLS on the OpenLDAP for CentOS 6.6 & 7 Thanks again.
Hi
Thanks for such a nice article.
Do you know how to configure openldap with mysql backend, Password Policy with replication (syncrepl)
I am new to this. pls excuse my dumb question.
In other online posts that i have seen, they ask to configure slapd.conf file but here you dont do that. Instead you are doing your config in config.ldif file. What’s the difference between the two approaches?
Very useful article. Waiting for the next part..
Waiting for next LDAP article…. π
You mention that the checksum error on “/etc/openldap/slapd.d/cn=config/olcDatabase={1}monitor.ldif” and “..{2}bdb.ldif” can be ignored “for now”. I agree, I get the message on my system but the ldap server is functioning fine.
But I would like to correct the crc32 checkum now. Can you tell us how to deal with this error?
This steps are done i was successfully configured in centos6.6 version , but i need to configured the client authentication steps
i got the result when i giving this command ” ldapsearch -x -b “dc=goldenjohn,dc=com”
but my doubt is i can’t view the user when i giving the ” getent passwd” command
1 . I can able to view the “getent passwd “in older version centos 5.8 , But i was not seeing the centos 6.6 ,
2. When i create any users in older version openlldap (centos 5.8) , i can able to login the super user in command prompt at the same openldapserver (su – username) , But i can’t able to login in locally configured server in openldap(centos6.6) using the super users ( su – ) its showing the error message like this “user golden does not exist” .
this command result : ldapsearch -x -b “dc=goldenjohn,dc=com”
dn: uid= golden,ou=People,dc=goldenjohn,dc=com
uid: golden
cn: golden
mail: golden@goldenjohn.om
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: shadowAccount
userPassword;: e1NTSEF9dTJCbTV1YUhJK205MBRN2pRbmNybkdJdnNvc2x5UTUg
shadowLastChange: 16443
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 506
gidNumber: 502
homeDirectory: /home/golden
# search result
search : 1
result : 0 Success
I was waiting for next steps to configure in client authentication with the TLS .
DO NOT MODIFY ldif-files in /etc/openldap/slapd.d manually. Use ldapmodify instead.
Great tutorial.
Well done.
Hello,
I have some trouble in adding the password.
You said to: vi /etc/openldap/slapd.d/cn=config.ldif and modify olcRootPW: {SSHA}1pgok6qWn24lpBkVreTDboTr81rg4QC6.
But i can’t find olcRootPW in cn=config.ldif. Do i need to add the olcRootPW line with my password?
Hi,
Thank you and Thank you again to share with you knowledge!
As always it’s brilliant and clear. I thinl as the other readers, I’m waitinng few more of your “news” about OpenLdap. We know, now, what it is, how it works, with your big help. Can we see few options of it, like implementing TLS, but as well how to use it on different platform. Let’s imagine we have our OpenLdap server on, let’s say one of our prefered Linux server and after implementing, how will we do for :
– having a master/slave (read only or copy of the master OpenLdap server, kind of redundancy) ?
– “connecting” different kind of *nix systems for using it (Solaris, HP/UX, AIX…) ?
– using this brand new OpenLdap server for authentificating the users who wants to connect/login on Win2008/12-R2.
In fact using this new OpenLdap server as our uniq source for User authentification for our Lab ?
A BIG thanks AGAIN for your Brilliant work and thanks for sharing with us your knowledge.
All the best
Regards
Erix
hi,
nice article
rather than create a new structure, t is it possible to import an existing structure associate whit the users and all…?
what inconveniant or advantage?
@Tarun, yes, add the value yourself. It should be in there.
Thanks very useful to deploy it.
Ramesh if you giving the openldap documents , installation and configuration steps in your blogs means its very useful for everyone
Installation in server side and client side
Need client with TLS login authentication methods and steps , I was eagerly waiting for your input on this topic , Kindly reply back because i was already demonstrate this on partially.
Hello, When i the command : ldapadd -x -W -D “cn=ramesh,dc=thegeekstuff,dc=com” -f base.ldif and when i enter the password i get the following error : ldap_bind: Invalid credentials (49) .
Seems you are using the wrong password. Which one are you using? You should use the LDAP admin password you made yourself. Note: not the encrypted one ({SSHA}xxxxxxxxxxxxxxx) but the “readable” one.
I used the “readable” but i still get the same error ldap_bind: Invalid credentials (49)
π
Yeah it’s working fine now thanks. Do you have an article on how to add users and groups?
Kindly mentioned this installation was supported whether redhat 7 / centos 7
I have done it the centos 6.6 openldap installation , refer my blog http://sysadmin3.blogspot.in/
Many Thanks
Golden John S
Would LOVE so get a notification or something when the next article about client configuration is up! Thanks a ton for the article it was extremely helpful!
Take the hash output of the above command and add it to the oclRootPW parameter in the config.ldif file as shown below.
# vi /etc/openldap/slapd.d/cn=config.ldif
olcRootPW: {SSHA}1pgok6qWn24lpBkVreTDboTr81rg4QC6
================================
as olcRootPW: will come under root DN and root dn will be at config.ldif, instead it must be at olcDatabase={2}bdb.ldi.
I was getting the error:
ldap_add: Type or value exists (20)
additional info: objectClass: value #2 provided more than once
When adding base.ldif. Turns out I needed a blank line between entries. In my case.
dn: dc=lava, dc=com
objectClass: dcObject
objectClass: organization
o: lava.com
dc: lava
dn: ou=users, dc=lava, dc=com
objectClass: organizationalUnit
objectClass: top
ou: users
dn: ou=groups, dc=lava, dc=com
objectClass: organizationalUnit
objectClass: top
ou: groups
Very helpful. Thanks.
A bit to tidy up. In base.ldif file, you get this error.
ldapadd: attributeDescription “dn”: (possible missing newline after line 9, entry “dc=xxx,dc=com”?)
Solution
Add a new like before each of the “dn”, solve the problem.
For those do not have the base.ldif just do a copy and paste and create a new file :0
Thanks for the article !!! very helpful !!!!!
This isn’t the first time I’ve used your howtos.
Thanks Much.
once I set this up how do I get it to act as a backup server (slave) to the current master LDAP server running Xandros (very old and being replaced)
Thanks for the guide! however I hit with error on the olcRootPW which after I put in {2}bdb.ldif, it solved the error.
and I hit with error on the base.ldif section which I need to enter empty lines between the dc, users and groups then it fixed the error.
Thanks for the info.
You recommended placing the olcRootPW in /etc/openldap/slapd.d/cn=config.ldif but that actually failed, says it has to go under the Suffix. I moved it to the other file and it works fine now.
I tried creating a second dn set for example.com and now I always get credential errors. Do I need to create a 2nd root password for the 2nd domain? How does that work?
Did you ever create the 2nd article on adding users and groups?
Thanks for your help. Thanks for your site, I learn a lot from you.
Bob
Good one, Thanks!
Hi sir,
It is very helpful and clearly understood. Many thanks for great help!!!
Br,
Raghuveer.
It really helped me a lot!! Thank u very much, for taking the time to explain this kind of stuff. I really appreciate it. Once againt, Thank you.