{"id":6099,"date":"2016-07-31T16:21:20","date_gmt":"2016-07-31T08:21:20","guid":{"rendered":"http:\/\/rmohan.com\/?p=6099"},"modified":"2016-07-31T16:21:20","modified_gmt":"2016-07-31T08:21:20","slug":"connect-rhel7-to-an-open-ldap-server","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6099","title":{"rendered":"CONNECT RHEL7 TO AN OPEN LDAP SERVER"},"content":{"rendered":"<p>e LDAP server will be named instructor.example.com in this procedure.<\/p>\n<p>Install the following packages:<\/p>\n<p># yum install -y openldap openldap-clients openldap-servers migrationtools net-tools.x86_64<br \/>\nGenerate a LDAP password from a secret key (using redhat):<\/p>\n<p># slappasswd -s redhat -n > \/etc\/openldap\/passwd<br \/>\nGenerate a X509 certificate valid for 365 days:<\/p>\n<p># openssl req -new -x509 -nodes -out \/etc\/openldap\/certs\/cert.pem -keyout \/etc\/openldap\/certs\/priv.pem -days 365<br \/>\nGenerating a 2048 bit RSA private key<br \/>\n&#8230;..+++<br \/>\n&#8230;&#8230;&#8230;&#8230;..+++<br \/>\nwriting new private key to &#8216;\/etc\/openldap\/certs\/priv.pem&#8217;<br \/>\n&#8212;&#8211;<br \/>\nYou are about to be asked to enter information that will be incorporated<br \/>\ninto your certificate request.<br \/>\nWhat you are about to enter is what is called a Distinguished Name or a DN.<br \/>\nThere are quite a few fields but you can leave some blank<br \/>\nFor some fields there will be a default value,<br \/>\nIf you enter &#8216;.&#8217;, the field will be left blank.<br \/>\n&#8212;&#8211;<br \/>\nCountry Name (2 letter code) [XX]:<br \/>\nState or Province Name (full name) []:<br \/>\nLocality Name (eg, city) [Default City]:<br \/>\nOrganization Name (eg, company) [Default Company Ltd]:<br \/>\nOrganizational Unit Name (eg, section) []:<br \/>\nCommon Name (eg, your name or your server&#8217;s hostname) []:instructor.example.com<br \/>\nEmail Address []:<br \/>\nSecure the content of the \/etc\/openldap\/certs directory:<\/p>\n<p># cd \/etc\/openldap\/certs<br \/>\n# chown ldap:ldap *<br \/>\n# chmod 600 priv.pem<br \/>\nPrepare the LDAP database:<\/p>\n<p>cp \/usr\/share\/openldap-servers\/DB_CONFIG.example \/var\/lib\/ldap\/DB_CONFIG<br \/>\nGenerate database files (don\u2019t worry about error messages!):<\/p>\n<p># slaptest<br \/>\n53d61aab hdb_db_open: database &#8220;dc=my-domain,dc=com&#8221;: db_open(\/var\/lib\/ldap\/id2entry.bdb) failed: No such file or directory (2).<br \/>\n53d61aab backend_startup_one (type=hdb, suffix=&#8221;dc=my-domain,dc=com&#8221;): bi_db_open failed! (2)<br \/>\nslap_startup failed (test would succeed using the -u switch)<br \/>\nChange LDAP database ownership:<\/p>\n<p># chown ldap:ldap \/var\/lib\/ldap\/*<br \/>\nActivate the slapd service at boot:<\/p>\n<p># systemctl enable slapd<br \/>\nStart the slapd service:<\/p>\n<p># systemctl start slapd<br \/>\nCheck the LDAP activity:<\/p>\n<p># netstat -lt | grep ldap<br \/>\ntcp        0      0 0.0.0.0:ldap            0.0.0.0:*               LISTEN<br \/>\ntcp6       0      0 [::]:ldap               [::]:*                  LISTEN<br \/>\nTo start the configuration of the LDAP server, add the cosine &#038; nis LDAP schemas:<\/p>\n<p># cd \/etc\/openldap\/schema<br \/>\n# ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -D &#8220;cn=config&#8221; -f cosine.ldif SASL\/EXTERNAL authentication started<br \/>\nSASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth<br \/>\nSASL SSF: 0<br \/>\nadding new entry &#8220;cn=cosine,cn=schema,cn=config&#8221;<br \/>\n# ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -D &#8220;cn=config&#8221; -f nis.ldif SASL\/EXTERNAL authentication started<br \/>\nSASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth<br \/>\nSASL SSF: 0<br \/>\nadding new entry &#8220;cn=nis,cn=schema,cn=config&#8221;<br \/>\nThen, create the \/etc\/openldap\/changes.ldif file and paste the following lines (replace password with the previously created password):<\/p>\n<p>To get the password which was previously generated:<\/p>\n<p># cat \/etc\/openldap\/passwd<br \/>\n{SSHA}98bGGGdL+aj\/TFVayaTsKj\/xkfDZaYsRua1pge<br \/>\ndn: olcDatabase={2}hdb,cn=config<br \/>\nchangetype: modify<br \/>\nreplace: olcSuffix<br \/>\nolcSuffix: dc=example,dc=com<\/p>\n<p>dn: olcDatabase={2}hdb,cn=config<br \/>\nchangetype: modify<br \/>\nreplace: olcRootDN<br \/>\nolcRootDN: cn=Manager,dc=example,dc=com<\/p>\n<p>dn: olcDatabase={2}hdb,cn=config<br \/>\nchangetype: modify<br \/>\nreplace: olcRootPW<br \/>\nolcRootPW: {SSHA}98bGGGdL+aj\/TFVayaTsKj\/xkfDZaYsRua1pge<\/p>\n<p>dn: cn=config<br \/>\nchangetype: modify<br \/>\nreplace: olcTLSCertificateFile<br \/>\nolcTLSCertificateFile: \/etc\/openldap\/certs\/cert.pem<\/p>\n<p>dn: cn=config<br \/>\nchangetype: modify<br \/>\nreplace: olcTLSCertificateKeyFile<br \/>\nolcTLSCertificateKeyFile: \/etc\/openldap\/certs\/priv.pem<\/p>\n<p>dn: cn=config<br \/>\nchangetype: modify<br \/>\nreplace: olcLogLevel<br \/>\nolcLogLevel: -1<\/p>\n<p>dn: olcDatabase={1}monitor,cn=config<br \/>\nchangetype: modify<br \/>\nreplace: olcAccess<br \/>\nolcAccess: {0}to * by dn.base=&#8221;gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=authd by dn.base=&#8221;cn=Manager,dc=example,dc=comd by * none<br \/>\nSend the new configuration to the slapd server:<\/p>\n<p># ldapmodify -Y EXTERNAL -H ldapi:\/\/\/ -f \/etc\/openldap\/changes.ldif SASL\/EXTERNAL authentication started<br \/>\nSASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth<br \/>\nSASL SSF: 0<br \/>\nmodifying entry &#8220;olcDatabase={2}hdb,cn=config&#8221;<br \/>\nmodifying entry &#8220;olcDatabase={2}hdb,cn=config&#8221;<br \/>\nmodifying entry &#8220;olcDatabase={2}hdb,cn=config&#8221;<br \/>\nmodifying entry &#8220;cn=config&#8221;<br \/>\nmodifying entry &#8220;cn=config&#8221;<br \/>\nmodifying entry &#8220;cn=config&#8221;<br \/>\nmodifying entry &#8220;olcDatabase={1}monitor,cn=config&#8221;<br \/>\nCreate the \/etc\/openldap\/base.ldif file and paste the following lines:<\/p>\n<p>dn: dc=example,dc=com<br \/>\ndc: example<br \/>\nobjectClass: top<br \/>\nobjectClass: domain<\/p>\n<p>dn: ou=People,dc=example,dc=com<br \/>\nou: People<br \/>\nobjectClass: top<br \/>\nobjectClass: organizationalUnit<\/p>\n<p>dn: ou=Group,dc=example,dc=com<br \/>\nou: Group<br \/>\nobjectClass: top<br \/>\nobjectClass: organizationalUnit<br \/>\nBuild the structure of the directory service:<\/p>\n<p># ldapadd -x -w redhat -D cn=Manager,dc=example,dc=com -f base.ldif adding new entry &#8220;dc=example,dc=com&#8221;<br \/>\nadding new entry &#8220;ou=People,dc=example,dc=com&#8221;<br \/>\nadding new entry &#8220;ou=Group,dc=example,dc=com&#8221;<br \/>\nCreate two users for testing:<\/p>\n<p># mkdir \/home\/guests<br \/>\n# useradd -d \/home\/guests\/ldapuser01 ldapuser01<br \/>\n# passwd ldapuser01 Changing password for user ldapuser01.<br \/>\nNew password: user01ldap<br \/>\nRetype new password: user01ldap<br \/>\npasswd: all authentication tokens updated successfully.<br \/>\n# useradd -d \/home\/guests\/ldapuser02 ldapuser02<br \/>\n# passwd ldapuser02 Changing password for user ldapuser02.<br \/>\nNew password: user02ldap<br \/>\nRetype new password: user02ldap<br \/>\npasswd: all authentication tokens updated successfully.<br \/>\nGo to the directory for the migration of the user accounts:<\/p>\n<p># cd \/usr\/share\/migrationtools<br \/>\nEdit the migrate_common.ph file and replace in the following lines:<\/p>\n<p>$DEFAULT_MAIL_DOMAIN = &#8220;example.com&#8221;;<br \/>\n$DEFAULT_BASE = &#8220;dc=example,dc=com&#8221;;<br \/>\nCreate the current users in the directory service:<\/p>\n<p># grep &#8220;:10[0-9][0-9]&#8221; \/etc\/passwd > passwd<br \/>\n# .\/migrate_passwd.pl passwd users.ldif<br \/>\n# ldapadd -x -w redhat -D cn=Manager,dc=example,dc=com -f users.ldif<br \/>\nadding new entry &#8220;uid=ldapuser01,ou=People,dc=example,dc=com&#8221;<br \/>\nadding new entry &#8220;uid=ldapuser02,ou=People,dc=example,dc=com&#8221;<br \/>\n# grep &#8220;:10[0-9][0-9]&#8221; \/etc\/group > group<br \/>\n# .\/migrate_group.pl group groups.ldif<br \/>\n# ldapadd -x -w redhat -D cn=Manager,dc=example,dc=com -f groups.ldif<br \/>\nadding new entry &#8220;cn=ldapuser01,ou=Group,dc=example,dc=com&#8221;<br \/>\nadding new entry &#8220;cn=ldapuser02,ou=Group,dc=example,dc=com&#8221;<br \/>\nTest the configuration with the user called ldapuser01:<\/p>\n<p># ldapsearch -x cn=ldapuser01 -b dc=example,dc=com<br \/>\nAdd a new service to the firewall (ldap: port tcp 389):<\/p>\n<p># firewall-cmd &#8211;permanent &#8211;add-service=ldap<br \/>\nReload the firewall configuration:<\/p>\n<p># firewall-cmd &#8211;reload<br \/>\nEdit the \/etc\/rsyslog.conf file and add the following line:<\/p>\n<p>local4.* \/var\/log\/ldap.log<br \/>\nRestart the rsyslog service:<\/p>\n<p># systemctl restart rsyslog<br \/>\nEdit the hosts file on the server:<\/p>\n<p># cat \/etc\/hosts<br \/>\n192.168.56.106 instructor.example.com<br \/>\nLDAP Client configuration<\/p>\n<p>Add the same hosts file entry on the client:<\/p>\n<p># cat \/etc\/hosts<br \/>\n192.168.56.106 instructor.example.com<br \/>\nInstall the following packages:<\/p>\n<p># yum install -y openldap-clients nss-pam-ldapd<br \/>\nRun the authentication menu:<\/p>\n<p># authconfig-tui<br \/>\nChoose the following options:<\/p>\n<p>&#8211; Cache Information<br \/>\n&#8211; Use LDAP<br \/>\n&#8211; Use MD5 Passwords<br \/>\n&#8211; Use Shadow Passwords<br \/>\n&#8211; Use LDAP Authentication<br \/>\n&#8211; Local authorization is sufficient<br \/>\nIn the LDAP Settings, type:<\/p>\n<p>Use TLS<br \/>\nldap:\/\/instructor.example.com<br \/>\ndc=example,dc=com<br \/>\nNote: Don\u2019t use TLS if you specify ldaps.<\/p>\n<p>Put the LDAP server certificate into the \/etc\/openldap\/cacerts directory when asked.<\/p>\n<p>Open another terminal window, and  cd \/etc\/openldap\/cacerts.<\/p>\n<p>cd \/etc\/openldap\/cacerts<br \/>\nwget http:\/\/instructor.example.com\/cert.pem .<br \/>\nClose authconfig-tui.<\/p>\n<p>Test the connection to the LDAP server (the ldapuser02\u2018s line of the \/etc\/passwd file should be displayed):<\/p>\n<p># getent passwd ldapuser02<br \/>\nldapuser02:x:1001:1001:ldapuser02:\/home\/guests\/ldapuser02:\/bin\/bash<\/p>\n","protected":false},"excerpt":{"rendered":"<p>e LDAP server will be named instructor.example.com in this procedure.<\/p>\n<p>Install the following packages:<\/p>\n<p># yum install -y openldap openldap-clients openldap-servers migrationtools net-tools.x86_64 Generate a LDAP password from a secret key (using redhat):<\/p>\n<p># slappasswd -s redhat -n > \/etc\/openldap\/passwd Generate a X509 certificate valid for 365 days:<\/p>\n<p># openssl req -new -x509 -nodes -out [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6099"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6099"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6099\/revisions"}],"predecessor-version":[{"id":6100,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6099\/revisions\/6100"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}