{"id":11744,"date":"2019-03-16T04:22:46","date_gmt":"2019-03-16T04:22:46","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11744"},"modified":"2019-03-16T04:22:46","modified_gmt":"2019-03-16T04:22:46","slug":"how-to-install-openldap-server-for-centralized-authentication","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/16\/how-to-install-openldap-server-for-centralized-authentication\/","title":{"rendered":"How To Install OpenLDAP Server for Centralized Authentication"},"content":{"rendered":"<p><strong>Lightweight Directory Access Protocol<\/strong>\u00a0(<strong>LDAP<\/strong>\u00a0in short) is an industry standard, lightweight, widely used set of protocols for accessing directory services. A directory service is a shared information infrastructure for accessing, managing, organizing, and updating everyday items and network resources, such as users, groups, devices, emails addresses, telephone numbers, volumes and many other objects.<\/p>\n<p>The\u00a0<strong>LDAP<\/strong>\u00a0information model is based on entries. An entry in a LDAP directory represents a single unit or information and is uniquely identified by what is called a\u00a0<strong>Distinguished Name<\/strong>\u00a0(<strong>DN<\/strong>). Each of the entry\u2019s attributes has a type and one or more values.<\/p>\n<p>An attribute is a piece of information associated with an entry. The types are typically mnemonic strings, such as \u201c<strong>cn<\/strong>\u201d for common name, or \u201c<strong>mail<\/strong>\u201d for email address. Each attribute is assigned one or more values consisting in a space-separated list.<\/p>\n<p>The following is an illustration of how information is arranged in the\u00a0<strong>LDAP<\/strong>\u00a0directory.<\/p>\n<div id=\"attachment_31366\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/ldap-information-model.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31366\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/ldap-information-model.png\" sizes=\"auto, (max-width: 773px) 100vw, 773px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/ldap-information-model.png 773w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/ldap-information-model-768x500.png 768w\" alt=\"Ldap Information Model\" width=\"773\" height=\"503\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Ldap Information Model<\/p>\n<\/div>\n<p><center><\/center>In this article, we will show how to install and configure\u00a0<strong>OpenLDAP<\/strong>\u00a0server for centralized authentication in\u00a0<strong>Ubuntu 16.04\/18.04<\/strong>\u00a0and\u00a0<strong>CentOS 7<\/strong>.<\/p>\n<h3>Step 1: Installing LDAP Server<\/h3>\n<p><strong>1.<\/strong>\u00a0First start by installing\u00a0<strong>OpenLDAP<\/strong>, an open source implementation of\u00a0<strong>LDAP<\/strong>\u00a0and some traditional LDAP management utilities using the following commands.<\/p>\n<pre># yum install openldap openldap-servers\t    #CentOS 7\r\n$ sudo apt install slapd ldap-utils\t    #Ubuntu 16.04\/18.04\r\n<\/pre>\n<p>On\u00a0<strong>Ubuntu<\/strong>, during the package installation, you will be prompted to enter the password for the admin entry in your LDAP directory, set a secure password and confirm it.<\/p>\n<div id=\"attachment_31367\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/configure-slapd-enter-admin-password.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31367\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/configure-slapd-enter-admin-password.png\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/configure-slapd-enter-admin-password.png 802w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/configure-slapd-enter-admin-password-768x439.png 768w\" alt=\"Configure Slapd Admin Password\" width=\"802\" height=\"458\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Configure Slapd Admin Password<\/p>\n<\/div>\n<p>When the installation is complete, you can start the service as explained next.<\/p>\n<p><strong>2.<\/strong>\u00a0On\u00a0<strong>CentOS 7<\/strong>, run the following commands to start the\u00a0<strong>openldap<\/strong>\u00a0server daemon, enable it to auto-start at boot time and check if its up and running (on\u00a0<strong>Ubuntu<\/strong>\u00a0the service should be auto-started under systemd, you can simply check its status):<\/p>\n<pre>$ sudo systemctl start slapd\r\n$ sudo systemctl enable slapd\r\n$ sudo systemctl status slapd\r\n<\/pre>\n<p><strong>3.<\/strong>\u00a0Next, allow requests to the\u00a0<strong>LDAP<\/strong>\u00a0server daemon through the firewall as shown.<\/p>\n<pre># firewall-cmd --add-service=ldap    #CentOS 7\r\n$ sudo ufw allow ldap                #Ubuntu 16.04\/18.04\r\n<\/pre>\n<h3>Step 2: Configuring LDAP Server<\/h3>\n<p><strong>Note<\/strong>: It is not recommended to manually edit the LDAP configuration, you need to add the configurations in a file and use the\u00a0<strong>ldapadd<\/strong>\u00a0or\u00a0<strong>ldapmodify<\/strong>\u00a0command to load them to the LDAP directory as shown below.<\/p>\n<p><strong>4.<\/strong>\u00a0Now create a OpenLDAP administrative user and assign a password for that user. In the below command, a hashed value is created for the given password, take note of it, you will use it in the LDAP configuration file.<\/p>\n<pre>$ slappasswd\r\n<\/pre>\n<div id=\"attachment_31368\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/create-ldap-admin-user-password.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31368\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/create-ldap-admin-user-password.png\" alt=\"Create Ldap Admin User\" width=\"542\" height=\"97\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Create Ldap Admin User<\/p>\n<\/div>\n<p><strong>5.<\/strong>\u00a0Then create an\u00a0<strong>LDIF<\/strong>\u00a0file (<strong>ldaprootpasswd.ldif<\/strong>) which is used to add an entry to the LDAP directory.<\/p>\n<pre>$ sudo vim ldaprootpasswd.ldif\r\n<\/pre>\n<p>Add the following contents in it:<\/p>\n<pre>dn: olcDatabase={0}config,cn=config\r\nchangetype: modify\r\nadd: olcRootPW\r\nolcRootPW: {SSHA}PASSWORD_CREATED\r\n<\/pre>\n<p>explaining the attribute-value pairs above:<\/p>\n<ul>\n<li><strong>olcDatabase<\/strong>: indicates a specific database instance name and can be typically found inside\u00a0<strong>\/etc\/openldap\/slapd.d\/cn=config<\/strong>.<\/li>\n<li><strong>cn=config<\/strong>: indicates global config options.<\/li>\n<li><strong>PASSWORD<\/strong>: is the hashed string obtained while creating the administrative user.<\/li>\n<\/ul>\n<p><strong>6.<\/strong>\u00a0Next, add the corresponding LDAP entry by specifying the URI referring to the ldap server and the file above.<\/p>\n<pre>$ sudo ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f ldaprootpasswd.ldif  \r\n<\/pre>\n<div id=\"attachment_31369\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/add-paramters-from-root-password-file.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31369\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/add-paramters-from-root-password-file.png\" sizes=\"auto, (max-width: 932px) 100vw, 932px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/add-paramters-from-root-password-file.png 932w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/add-paramters-from-root-password-file-768x111.png 768w\" alt=\"Add Parameters from Root Password File\" width=\"932\" height=\"135\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Add Parameters from Root Password File<\/p>\n<\/div>\n<h3>Step 3: Configuring LDAP Database<\/h3>\n<p><strong>7.<\/strong>\u00a0Now copy the sample database configuration file for\u00a0<strong>slapd<\/strong>\u00a0into the\u00a0<strong>\/var\/lib\/ldap<\/strong>\u00a0directory, and set the correct permissions on the file.<\/p>\n<pre>$ sudo cp \/usr\/share\/openldap-servers\/DB_CONFIG.example \/var\/lib\/ldap\/DB_CONFIG\r\n$ sudo chown -R ldap:ldap \/var\/lib\/ldap\/DB_CONFIG\r\n$ sudo systemctl restart slapd\r\n<\/pre>\n<p><strong>8.<\/strong>\u00a0Next, import some basic LDAP schemas from the\u00a0<strong>\/etc\/openldap\/schema<\/strong>\u00a0directory as follows.<\/p>\n<pre>$ sudo ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f \/etc\/openldap\/schema\/cosine.ldif \r\n$ sudo ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f \/etc\/openldap\/schema\/nis.ldif\r\n$ sudo ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f \/etc\/openldap\/schema\/inetorgperson.ldif\r\n<\/pre>\n<p><strong>9.<\/strong>\u00a0Now add your domain in the LDAP database and create a file called\u00a0<strong>ldapdomain.ldif<\/strong>\u00a0for your domain.<\/p>\n<pre>$ sudo vim ldapdomain.ldif \r\n<\/pre>\n<p>Add the following content in it (replace example with your domain and PASSWORD with the hashed value obtained before):<\/p>\n<pre>dn: olcDatabase={1}monitor,cn=config\r\nchangetype: modify\r\nreplace: olcAccess\r\nolcAccess: {0}to * by dn.base=\"gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\"\r\n  read by dn.base=\"cn=Manager,<strong>dc=example<\/strong>,dc=com\" read by * none\r\n\r\ndn: olcDatabase={2}hdb,cn=config\r\nchangetype: modify\r\nreplace: olcSuffix\r\nolcSuffix: <strong>dc=example<\/strong>,dc=com\r\n\r\ndn: olcDatabase={2}hdb,cn=config\r\nchangetype: modify\r\nreplace: olcRootDN\r\nolcRootDN: cn=Manager,<strong>dc=example<\/strong>,dc=com\r\n\r\ndn: olcDatabase={2}hdb,cn=config\r\nchangetype: modify\r\nadd: olcRootPW\r\nolcRootPW: {SSHA}PASSWORD\r\n\r\ndn: olcDatabase={2}hdb,cn=config\r\nchangetype: modify\r\nadd: olcAccess\r\nolcAccess: {0}to attrs=userPassword,shadowLastChange by\r\n  dn=\"cn=Manager,<strong>dc=example<\/strong>,dc=com\" write by anonymous auth by self write by * none\r\nolcAccess: {1}to dn.base=\"\" by * read\r\nolcAccess: {2}to * by dn=\"cn=Manager,dc=example,dc=com\" write by * read\r\n<\/pre>\n<p><strong>10.<\/strong>\u00a0Then add the above configuration to the LDAP database with the following command.<\/p>\n<pre>$ sudo ldapmodify -Y EXTERNAL -H ldapi:\/\/\/ -f ldapdomain.ldif\r\n<\/pre>\n<div id=\"attachment_31370\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/load-domain-configuration.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31370\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/load-domain-configuration.png\" sizes=\"auto, (max-width: 932px) 100vw, 932px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/load-domain-configuration.png 932w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/load-domain-configuration-768x236.png 768w\" alt=\"Load Domain Configuration\" width=\"932\" height=\"287\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Load Domain Configuration<\/p>\n<\/div>\n<p><strong>11.<\/strong>\u00a0In this step, we need to add some entries to our\u00a0<strong>LDAP<\/strong>\u00a0directory. Create another file called\u00a0<strong>baseldapdomain.ldif<\/strong>\u00a0with the following content.<\/p>\n<pre>dn: dc=example,dc=com\r\nobjectClass: top\r\nobjectClass: dcObject\r\nobjectclass: organization\r\no: example com\r\ndc: example\r\n\r\ndn: cn=Manager,dc=example,dc=com\r\nobjectClass: organizationalRole\r\ncn: Manager\r\ndescription: Directory Manager\r\n\r\ndn: ou=People,dc=example,dc=com\r\nobjectClass: organizationalUnit\r\nou: People\r\n\r\ndn: ou=Group,dc=example,dc=com\r\nobjectClass: organizationalUnit\r\nou: Group \r\n<\/pre>\n<p>Save the file and then add the entries to the LDAP directory.<\/p>\n<pre>$ sudo ldapadd -Y EXTERNAL -x -D cn=Manager,dc=example,dc=com -W -f baseldapdomain.ldif\r\n<\/pre>\n<p><strong>12.<\/strong>\u00a0The next step is to create a LDAP user for\u00a0<strong>example<\/strong>,\u00a0<strong>tecmint<\/strong>, and set a password for this user as follows.<\/p>\n<pre>$ sudo useradd tecmint\r\n$ sudo passwd tecmint\r\n<\/pre>\n<p><strong>13.<\/strong>\u00a0Then create the definitions for a LDAP group in a file called\u00a0<strong>ldapgroup.ldif<\/strong>\u00a0with the following content.<\/p>\n<pre>dn: cn=Manager,ou=Group,dc=example,dc=com\r\nobjectClass: top\r\nobjectClass: posixGroup\r\ngidNumber: 1005\r\n<\/pre>\n<p>In the above configuration,\u00a0<strong>gidNumber<\/strong>\u00a0is the\u00a0<strong>GID<\/strong>\u00a0in\u00a0<strong>\/etc\/group<\/strong>\u00a0for\u00a0<strong>tecmint<\/strong>\u00a0and add it to the OpenLDAP directory.<\/p>\n<pre>$ sudo ldapadd -Y EXTERNAL -x  -W -D \"cn=Manager,dc=example,dc=com\" -f ldapgroup.ldif\r\n<\/pre>\n<p><strong>14.<\/strong>\u00a0Next, create another\u00a0<strong>LDIF<\/strong>\u00a0file called\u00a0<strong>ldapuser.ldif<\/strong>\u00a0and add the definitions for user\u00a0<strong>tecmint<\/strong>.<\/p>\n<pre>dn: uid=tecmint,ou=People,dc=example,dc=com\r\nobjectClass: top\r\nobjectClass: account\r\nobjectClass: posixAccount\r\nobjectClass: shadowAccount\r\ncn: tecmint\r\nuid: tecmint\r\nuidNumber: 1005\r\ngidNumber: 1005\r\nhomeDirectory: \/home\/tecmint\r\nuserPassword: {SSHA}PASSWORD_HERE\r\nloginShell: \/bin\/bash\r\ngecos: tecmint\r\nshadowLastChange: 0\r\nshadowMax: 0\r\nshadowWarning: 0\r\n<\/pre>\n<p>then load fthe configuration to the LDAP directory.<\/p>\n<pre>$ ldapadd -Y EXTERNAL  -x -D cn=Manager,dc=example,dc=com -W -f  ldapuser.ldif\r\n<\/pre>\n<p>Once you have setup a central server for authentication, the final part is to enable the client to authenticate using LDAP as explained in this guide:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/configure-ldap-client-to-connect-external-authentication\/\" target=\"_blank\" rel=\"noopener\">How to Configure LDAP Client to Connect External Authentication<\/a><\/li>\n<\/ol>\n<p>For more information, see the appropriate documentation from\u00a0<a href=\"https:\/\/www.openldap.org\/doc\/\" target=\"_blank\" rel=\"nofollow noopener\">OpenLDAP Software document catalog<\/a>\u00a0and Ubuntu users can refer to the\u00a0<a href=\"https:\/\/help.ubuntu.com\/lts\/serverguide\/openldap-server.html.en\" target=\"_blank\" rel=\"nofollow noopener\">OpenLDAP server guide<\/a>.<\/p>\n<h5>Summary<\/h5>\n<p><strong>OpenLDAP<\/strong>\u00a0is a open source implementation of LDAP in Linux. In this article, we have shown how to install and configure OpenLDAP server for centralized authentication, in Ubuntu 16.04\/18.04 and CentOS 7. If you have a question or thoughts to share, do not hesitate to reach us via the comment form below.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/install-openldap-server-for-centralized-authentication\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lightweight Directory Access Protocol\u00a0(LDAP\u00a0in short) is an industry standard, lightweight, widely used set of protocols for accessing directory services. A directory service is a shared information infrastructure for accessing, managing, organizing, and updating everyday items and network resources, such as users, groups, devices, emails addresses, telephone numbers, volumes and many other objects. The\u00a0LDAP\u00a0information model is &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/16\/how-to-install-openldap-server-for-centralized-authentication\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How To Install OpenLDAP Server for Centralized Authentication&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11744","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11744","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11744"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11744\/revisions"}],"predecessor-version":[{"id":11745,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11744\/revisions\/11745"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}