{"id":4771,"date":"2019-11-15T23:19:19","date_gmt":"2019-11-15T20:19:19","guid":{"rendered":"https:\/\/kifarunix.com\/?p=4771"},"modified":"2024-03-12T23:13:43","modified_gmt":"2024-03-12T20:13:43","slug":"configure-sssd-for-openldap-authentication-on-centos-8","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/configure-sssd-for-openldap-authentication-on-centos-8\/","title":{"rendered":"Configure SSSD for OpenLDAP Authentication on CentOS 8"},"content":{"rendered":"\n<p>In this guide, we are going to demonstrate how to configure SSSD for OpenLDAP Authentication on CentOS 8. In our previous guides, we have covered how to install and setup OpenLDAP on CentOS 8 as well how to configure SUDO via OpenLDAP. See the links below;<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-and-setup-openldap-on-centos-8\/\" target=\"_blank\">Install and Setup OpenLDAP on CentOS 8<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/how-to-configure-sudo-via-openldap-server\/\" target=\"_blank\">How to Configure SUDO via OpenLDAP Server<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configuring SSSD for OpenLDAP Authentication on CentOS 8<\/h2>\n\n\n\n<p><a href=\"https:\/\/docs.pagure.org\/SSSD.sssd\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"SSSD (opens in a new tab)\">SSSD<\/a>&nbsp;is an acronym for System Security Services Daemon. It provides access to different identity and authentication providers.<\/p>\n\n\n\n<p>In this demo, we are using OpenLDAP as our directory as well identity management server.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Run system update<\/h3>\n\n\n\n<p>To update your system packages, execute the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dnf update<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Install SSSD on CentOS 8<\/h3>\n\n\n\n<p>Once the system update is done, proceed to install SSSD and other SSSD tools.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dnf install sssd sssd-tools<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configuring SSSD for OpenLDAP Authentication on CentOS 8<\/h3>\n\n\n\n<p>Next, configure SSSD to allow authentication to your local system via OpenLDAP.<\/p>\n\n\n\n<p>SSSD doesn&#8217;t usually ship with any default configuration file. As such you need to create and configure it manually.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/sssd\/sssd.conf<\/code><\/pre>\n\n\n\n<p>Paste the content below into <strong>sssd.conf<\/strong> file. Be sure to make the relevant substitutions replacing your domain components appropriately.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\n[sssd]\nservices = nss, pam, sudo\nconfig_file_version = 2\ndomains = default\n\n[sudo]\n\n[nss]\n\n[pam]\noffline_credentials_expiration = 60\n\n[domain\/default]\nldap_id_use_start_tls = True\ncache_credentials = True\nldap_search_base = dc=ldapmaster,dc=kifarunix-demo,dc=com\nid_provider = ldap\nauth_provider = ldap\nchpass_provider = ldap\naccess_provider = ldap\nsudo_provider = ldap\nldap_uri = ldap:\/\/ldapmaster.kifarunix-demo.com\nldap_default_bind_dn = cn=readonly,ou=system,dc=ldapmaster,dc=kifarunix-demo,dc=com\nldap_default_authtok = P@ssWOrd\nldap_tls_reqcert = demand\nldap_tls_cacert = \/etc\/pki\/tls\/cacert.crt\nldap_tls_cacertdir = \/etc\/pki\/tls\nldap_search_timeout = 50\nldap_network_timeout = 60\nldap_sudo_search_base = ou=SUDOers,dc=ldapmaster,dc=kifarunix-demo,dc=com\nldap_access_order = filter\nldap_access_filter = (objectClass=posixAccount)\n<\/code><\/pre>\n\n\n\n<p>Save and quit the configuration files. Be sure to make relevant changes accordingly.<\/p>\n\n\n\n<p>Note that we have also configured our OpenLDAP server to provide sudo rights as shown by the configurations;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\nservices = nss, pam, <strong>sudo<\/strong>\n...\n\n<strong>[sudo]<\/strong>\n...\n\n<strong>ldap_sudo_search_base = ou=SUDOers,dc=ldapmaster,dc=kifarunix-demo,dc=com<\/strong>\n<\/code><\/pre>\n\n\n\n<p><strong>If you are not using OpenLDAP for sudo rules<\/strong>, you can remove these configurations.<\/p>\n\n\n\n<p>Next, download the OpenLDAP server CA certificate and store it on the file specified by the <code>ldap_tls_cacert<\/code> directive on the sssd.conf file above.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>openssl s_client -connect ldapmaster.kifarunix-demo.com:636 -showcerts &lt; \/dev\/null | openssl x509 -text<\/code><\/pre>\n\n\n\n<p>Copy the certificate and paste it on the <strong><code>\/etc\/pki\/tls\/cacert.crt<\/code><\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/pki\/tls\/cacert.crt<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>-----BEGIN CERTIFICATE-----\nMIIFxzCCA6+gAwIBAgIUV+l4aOvMCLlNQRKOpt9YfxcxA8MwDQYJKoZIhvcNAQEL\nBQAwczELMAkGA1UEBhMCS0UxEDAOBgNVBAgMB05haXJvYmkxDDAKBgNVBAcMA05h\n...\n...\n5deiMlJkrYv7wZ0prq0QO5lduGBuD9UJvRa8LBV0GEAiHZL5PJOnREHObbAH907E\neixIJpkcC4wguMaXDNqIv6WGdQtRUyIP8tdByXYJGrbRW0K\/K9qEaIZhJiAES1Qy\n8U96RdYBpLvDctRch1kIfvnAVffTxmObAGI9n64O89p48kocJwNI\/XQNRg==\n-----END CERTIFICATE-----<\/code><\/pre>\n\n\n\n<p>Next, open the <code>\/etc\/openldap\/ldap.conf<\/code> configuration file and configure it as follows;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/openldap\/ldap.conf<\/code><\/pre>\n\n\n\n<p>Basically, you need to define the location of the CA certificate, the OpenLDAP search base, the URI and if you are providing SUDO via OpenLDAP, the SUDOers base.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>BASE    dc=ldapmaster,dc=kifarunix-demo,dc=com\nURI     ldaps:\/\/ldapmaster.kifarunix-demo.com:636\nSUDOERS_BASE    ou=SUDOers,dc=ldapmaster,dc=kifarunix-demo,dc=com\n...\n...\nTLS_CACERT      \/etc\/pki\/tls\/cacert.crt\n...<\/code><\/pre>\n\n\n\n<p>Save and quit the configuration file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Configure Name Service Switch and PAM on CentOS 8<\/h3>\n\n\n\n<p>Next, you need to update the NSS and PAM to use SSSD to manage authentication resources.<\/p>\n\n\n\n<p>In previous versions of CentOS, you would use tools like <code><strong>authconfig<\/strong><\/code> but this has since been replaced by tools like <code><strong>authselect<\/strong><\/code>.<\/p>\n\n\n\n<p><code>Authselect<\/code>&nbsp;is a utility that simplifies the configuration of user authentication&nbsp;especially while using SSSD for authentication.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Configure SSSD Profile<\/h4>\n\n\n\n<p>Authselect command when used to create an SSSD profile, will basically modify these files;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\/etc\/pam.d\/system-auth<\/li>\n\n\n\n<li>\/etc\/pam.d\/password-auth<\/li>\n\n\n\n<li>\/etc\/pam.d\/fingerprint-auth<\/li>\n\n\n\n<li>\/etc\/pam.d\/smartcard-auth<\/li>\n\n\n\n<li>\/etc\/pam.d\/postlogin<\/li>\n\n\n\n<li>\/etc\/nsswitch.conf<\/li>\n<\/ul>\n\n\n\n<p>Therefore, make a back up of these files just in case things don&#8217;t work out. Once you have backed up these files, remove them.<\/p>\n\n\n\n<p>Create an SSSD profile. This command will succeed only of you have removed the files above.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>authselect select sssd<\/code><\/pre>\n\n\n\n<p>Otherwise, you can overwrite the files by adding the <code>--force<\/code> option.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>authselect select sssd --force<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Backup stored at \/var\/lib\/authselect\/backups\/2019-12-08-19-05-16.yMO4TA\nProfile \"sssd\" was selected.\nThe following nsswitch maps are overwritten by the profile:\n- passwd\n- group\n- netgroup\n- automount\n- services\n\nMake sure that SSSD service is configured and enabled. See SSSD documentation for more information.<\/code><\/pre>\n\n\n\n<p>Next, for the system to fetch sudo rights from SSSD\/OpenLDAP, edit the <code>\/etc\/nsswitch.conf<\/code> to include the line below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudoers:    files sss<\/code><\/pre>\n\n\n\n<p>You can simply echo the line into the configuration file as shown below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>echo \"sudoers:    files sss\" &gt;&gt; \/etc\/nsswitch.conf<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure Automatic Home Directory Creation<\/h3>\n\n\n\n<p>To enable automatic home directory creation for user upon first login, you need to install the <code><strong>oddjob-mkhomedir<\/strong><\/code>, which provides the <code><strong>pam_oddjob_mkhomedir<\/strong><\/code> module to create a home directory for a user at login-time.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dnf install oddjob-mkhomedir<\/code><\/pre>\n\n\n\n<p>Start and enable oddjobd to run on system boot.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl enable --now oddjobd<\/code><\/pre>\n\n\n\n<p>Load the <code><strong>pam_oddjob_mkhomedir<\/strong><\/code> module in PAM auth file <code>\/etc\/pam.d\/system-auth<\/code> to enable auto home directory creation.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>echo \"session optional pam_oddjob_mkhomedir.so skel=\/etc\/skel\/ umask=0022\" &gt;&gt; \/etc\/pam.d\/system-auth<\/code><\/pre>\n\n\n\n<p>Restart oddjobd.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl restart oddjobd<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Running SSSD<\/h3>\n\n\n\n<p>Before you can start SSSD, you need to check configuration for any typos or permissions;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sssctl config-check<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>File ownership and permissions check failed. Expected root:root and 0600.<\/code><\/pre>\n\n\n\n<p>As per the check output, set the read\/write access to&nbsp;<code>\/etc\/sssd\/<\/code>&nbsp;for the owner (root).<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chown -R root: \/etc\/sssd<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chmod 600 -R \/etc\/sssd<\/code><\/pre>\n\n\n\n<p>The configuration is now done. Start and enable SSSD to run on system boot.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl enable --now sssd<\/code><\/pre>\n\n\n\n<p>Check the status.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl status sssd<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n\u25cf sssd.service - System Security Services Daemon\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/sssd.service; enabled; vendor preset: enabled)\n   Active: active (running) since Sun 2019-12-08 16:57:07 EAT; 42min ago\n Main PID: 779 (sssd)\n    Tasks: 3 (limit: 5073)\n   Memory: 60.6M\n   CGroup: \/system.slice\/sssd.service\n           \u251c\u2500779 \/usr\/sbin\/sssd -i --logger=files\n           \u251c\u2500800 \/usr\/libexec\/sssd\/sssd_be --domain implicit_files --uid 0 --gid 0 --logger=files\n           \u2514\u2500801 \/usr\/libexec\/sssd\/sssd_nss --uid 0 --gid 0 --logger=files\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Test OpenLDAP Authentication via SSSD<\/h3>\n\n\n\n<p>Assuming that you have already created your OpenLDAP users and groups ( if not check our guide on <a rel=\"noreferrer noopener\" aria-label=\"setting up OpenLDAP server on CentOS 8 (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-and-setup-openldap-on-centos-8\/\" target=\"_blank\">setting up OpenLDAP server on CentOS 8<\/a>), verify that you can login.<\/p>\n\n\n\n<p>First, confirm that you can see your LDAP username on your system using <code>id<\/code> command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>id johndoe<\/code><\/pre>\n\n\n\n<p>You should get an entry similar to;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>uid=1002(johndoe) gid=1002(johndoe) groups=1002(johndoe)<\/code><\/pre>\n\n\n\n<p>If you cant get the above output, be sure to check syslog logs as well as sssd logs. Otherwise, you can restart sssd;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl restart sssd<\/code><\/pre>\n\n\n\n<p>Check user again using <code>id<\/code> command.<\/p>\n\n\n\n<p>If all is well, Perform a local ssh authentication to test your LDAP authentication.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ssh -l johndoe localhost<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>The authenticity of host 'localhost (::1)' can't be established.\nECDSA key fingerprint is SHA256:iMRNJQa8gU0t6fHx6nzmAU+ZygA\/3J2BC6zzwzqfY4o.\nAre you sure you want to continue connecting (yes\/no)? yes\nWarning: Permanently added 'localhost' (ECDSA) to the list of known hosts.\njohndoe@localhost's password: \n&#91;johndoe@centos8 ~]$ pwd\n\/home\/johndoe<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Verify that you got sudo rights.<\/h3>\n\n\n\n<p>First, if you have assigned the user sudo rights, you can check by running the command below on your OpenLDAP server. Replace the domain components accordingly.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>export SUDOERS_BASE=ou=SUDOers,dc=ldapmaster,dc=kifarunix-demo,dc=com<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ldapsearch -b \"$SUDOERS_BASE\" -D cn=admin,dc=ldapmaster,dc=kifarunix-demo,dc=com -W -x<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n...\n# sudo, SUDOers, ldapmaster.kifarunix-demo.com\ndn: cn=sudo,ou=SUDOers,dc=ldapmaster,dc=kifarunix-demo,dc=com\nobjectClass: top\nobjectClass: sudoRole\ncn: sudo\nsudoUser: johndoe\nsudoHost: ALL\nsudoRunAsUser: ALL\nsudoCommand: ALL\n...\n<\/code><\/pre>\n\n\n\n<p>Next, on the client, try the sudo!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;johndoe@centos8 ~]$ sudo su -<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\nWe trust you have received the usual lecture from the local System\nAdministrator. It usually boils down to these three things:\n\n    #1) Respect the privacy of others.\n    #2) Think before you type.\n    #3) With great power comes great responsibility.\n\n[sudo] password for johndoe: \nLast login: Sun Dec  8 22:49:47 EAT 2019 from 192.168.56.1 on pts\/0\n[root@centos8 ~]#\n<\/code><\/pre>\n\n\n\n<p>If you have any thought about this guide, don&#8217;t hesitate to drop in comments section.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Other Related Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/how-to-create-openldap-member-groups\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">How to Create OpenLDAP Member Groups<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/kifarunix.com\/configure-sssd-for-openldap-client-authentication-on-debian-10-9\/\" target=\"_blank\">Configure SSSD for OpenLDAP Client Authentication on Debian 10\/9<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/kifarunix.com\/setup-openldap-server-with-ssl-tls-on-debian-10\/\" target=\"_blank\">Setup OpenLDAP Server with SSL\/TLS on Debian 10<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/kifarunix.com\/install-and-configure-openldap-server-on-fedora-29\/\" target=\"_blank\">Install and Configure OpenLDAP server on Fedora 29<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/kifarunix.com\/configure-openldap-client-on-debian-9-stretch\/\" target=\"_blank\">Configure OpenLDAP Client on Debian 9 Stretch<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/kifarunix.com\/install-and-configure-openldap-server-on-debian-9-stretch\/\" target=\"_blank\">Install and Configure OpenLDAP Server on Debian 9 Stretch<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we are going to demonstrate how to configure SSSD for OpenLDAP Authentication on CentOS 8. In our previous guides, we have covered<\/p>\n","protected":false},"author":1,"featured_media":10441,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,285,1099],"tags":[1221,1220,1142,1651,1650,286,1217,1131,1219],"class_list":["post-4771","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","category-directory-server","category-openldap","tag-authconfig","tag-authselect","tag-centos-8","tag-configure-sssd-for-openldap-authentication","tag-install-sssd-on-centos-8","tag-openldap","tag-openldap-sudo","tag-sssd","tag-sssd-on-centos-8","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/4771"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=4771"}],"version-history":[{"count":16,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/4771\/revisions"}],"predecessor-version":[{"id":21256,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/4771\/revisions\/21256"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/10441"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=4771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=4771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=4771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}