{"id":5838,"date":"2020-05-08T15:11:47","date_gmt":"2020-05-08T12:11:47","guid":{"rendered":"https:\/\/kifarunix.com\/?p=5838"},"modified":"2024-03-14T20:37:01","modified_gmt":"2024-03-14T17:37:01","slug":"configure-sssd-for-ldap-authentication-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/configure-sssd-for-ldap-authentication-on-ubuntu-20-04\/","title":{"rendered":"Configure SSSD for LDAP Authentication on Ubuntu 20.04"},"content":{"rendered":"\n<p>This guide will take you through how to install and configure SSSD for LDAP authentication on Ubuntu 20.04. <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.pagure.org\/SSSD.sssd\/\" target=\"_blank\">SSSD<\/a> (System Security Services Daemon) is a system service to access remote directories and authentication mechanisms such as an LDAP directory, an Identity Management (IdM) or Active Directory (AD) domain, or a Kerberos realm.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configuring SSSD for LDAP Authentication on Ubuntu 20.04<\/h2>\n\n\n\n<p>Assuming you already have a running OpenLDAP server, proceed with this guide to learn how to install and configure SSSD for LDAP authentication.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Run System Update<\/h3>\n\n\n\n<p>Ensure that your system package cache is up-to-date.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt update<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Install SSSD on Ubuntu 20.04<\/h3>\n\n\n\n<p>To install SSSD and other required SSSD tools on Ubuntu 20.04, run the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install sssd libpam-sss libnss-sss<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure SSSD\u00a0for OpenLDAP Authentication<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Create SSSD configuration file<\/h4>\n\n\n\n<p>SSSD do not ship with any configuration file by default. As such, you need to create your configuration file that defines your LDAP authentication specifics.<\/p>\n\n\n\n<p>Below is our sample configuration options;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/etc\/sssd\/sssd.conf<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n[sssd]\nservices = nss, pam\nconfig_file_version = 2\ndomains = default\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\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\/ssl\/certs\/ldapcacert.crt\nldap_tls_cacertdir = \/etc\/ssl\/certs\nldap_search_timeout = 50\nldap_network_timeout = 60\nldap_access_order = filter\nldap_access_filter = (objectClass=posixAccount)\n<\/code><\/pre>\n\n\n\n<p>Check the highlighted lines above and replace their values appropriately.<\/p>\n\n\n\n<p>For a comprehensive description of options used above, refer to&nbsp;<strong><code>man sssd.conf<\/code><\/strong> and <code><strong>man sssd-ldap<\/strong><\/code>.<\/p>\n\n\n\n<p>Once you are done with your configurations, save and exit the file.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Install OpenLDAP Server CA Certificate on Ubuntu 20.04 LDAP client<\/h4>\n\n\n\n<p>SSSD authentication can only work over an encrypted communication channel. Therefore, your OpenLDAP server must be configured SSL\/TLS.<\/p>\n\n\n\n<p>If you have done this already, download the CA certificate from the LDAP server to the LDAP client by executing the command below;<\/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 | sed -ne '\/-BEGIN CERTIFICATE-\/,\/-END CERTIFICATE-\/p'<\/code><\/pre>\n\n\n\n<p>if you are downloading the certificates from an OpenLDAP server listening on STARTTLS (port 389\/{tcp,udp}), use the command below instead;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>openssl s_client -connect ldapmaster.kifarunix-demo.com:389 -starttls ldap -showcerts &lt; \/dev\/null | openssl x509 -text | sed -ne '\/-BEGIN CERTIFICATE-\/,\/-END CERTIFICATE-\/p'<\/code><\/pre>\n\n\n\n<p>Copy the certificate part;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>-----BEGIN CERTIFICATE-----\nMIIDvzCCAqegAwIBAgIUc8imlOVhEej453dXtvacn7krg1MwDQYJKoZIhvcNAQEL\nBQAwbzELMAkGA1UEBhMCS0UxDDAKBgNVBAgMA05haTEMMAoGA1UEBwwDTWFpMRww\nGgYDVQQKDBNEZWZhdWx0IENvbXBhbnkgTHRkMSYwJAYDVQQDDB1sZGFwbWFzdGVy\n...\n...\nExJaMa6cJkIFmepJ6wGvk33DiLRZrAKT2\/11yswYm16mdpUynmx6pZvZizjxkq+c\nhegnowyEG4db\/NktY44v2ryIQdEclnKmhk23vmhgZxl1IUgev2tc\/\/JWPE9dXuP8\nUy7ivNi2PL6mBwxMpyi0zTopqTXSvi54APm48dd0JPsGLTIgPMc1WvaN7TsUeIBs\nIgf9K1e9M0Q+j2XEsTeCYVU\/v0Jt0kER0+V\/NM0IrDOX+6kRz6DNsZrwcMEf5Yvp\nARWZ\n-----END CERTIFICATE-----\n<\/code><\/pre>\n\n\n\n<p>As per our SSSD configuration, the LDAP CA certificate file is stored as <strong><code>\/etc\/ssl\/certs\/ldapcacert.crt<\/code><\/strong> on the client. <strong>Note<\/strong> that the location of the CA cert file might be different for your case.<\/p>\n\n\n\n<p>Therefore, copy the certificate above and place it in this file;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/ssl\/certs\/ldapcacert.crt<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>-----BEGIN CERTIFICATE-----\nMIIDvzCCAqegAwIBAgIUc8imlOVhEej453dXtvacn7krg1MwDQYJKoZIhvcNAQEL\nBQAwbzELMAkGA1UEBhMCS0UxDDAKBgNVBAgMA05haTEMMAoGA1UEBwwDTWFpMRww\nGgYDVQQKDBNEZWZhdWx0IENvbXBhbnkgTHRkMSYwJAYDVQQDDB1sZGFwbWFzdGVy\n...\n...\nExJaMa6cJkIFmepJ6wGvk33DiLRZrAKT2\/11yswYm16mdpUynmx6pZvZizjxkq+c\nhegnowyEG4db\/NktY44v2ryIQdEclnKmhk23vmhgZxl1IUgev2tc\/\/JWPE9dXuP8\nUy7ivNi2PL6mBwxMpyi0zTopqTXSvi54APm48dd0JPsGLTIgPMc1WvaN7TsUeIBs\nIgf9K1e9M0Q+j2XEsTeCYVU\/v0Jt0kER0+V\/NM0IrDOX+6kRz6DNsZrwcMEf5Yvp\nARWZ\n-----END CERTIFICATE-----\n<\/code><\/pre>\n\n\n\n<p>Verify the validity of the certificate;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>openssl s_client -connect ldapmaster.kifarunix-demo.com:389 -CAfile \/etc\/ssl\/certs\/ldapcacert.crt<\/code><\/pre>\n\n\n\n<p>If you get, <code><strong>Verification: OK<\/strong><\/code> or <code><strong>Verify return code: 0 (ok)<\/strong><\/code> on the command output, then you are all set.<\/p>\n\n\n\n<p>Next, open the&nbsp;<code><strong>\/etc\/ldap\/ldap.conf<\/strong><\/code>&nbsp;and replace the value of&nbsp;<strong><code>TLS_CACERT<\/code><\/strong>&nbsp;with the path to the CA certificate created above.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/ldap\/ldap.conf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>...\n# TLS certificates (needed for GnuTLS)\n#TLS_CACERT     \/etc\/ssl\/certs\/ca-certificates.crt\n<strong>TLS_CACERT      \/etc\/ssl\/certs\/ldapcacert.crt<\/strong><\/code><\/pre>\n\n\n\n<p>Save and close the configuration file.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Set Proper Permissions on SSSD configurations<\/h4>\n\n\n\n<p>After that, assign the root user read\/write access to&nbsp;<code>\/etc\/sssd\/<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chmod 600 -R \/etc\/sssd<\/code><\/pre>\n\n\n\n<p>Restart SSSD service<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl restart sssd<\/code><\/pre>\n\n\n\n<p>Check the status of SSSD to ensure that it is running.<\/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>\u25cf sssd.service - System Security Services Daemon\n     Loaded: loaded (\/lib\/systemd\/system\/sssd.service; enabled; vendor preset: enabled)\n     Active: active (running) since Fri 2020-05-08 11:38:21 EAT; 6s ago\n   Main PID: 7004 (sssd)\n      Tasks: 4 (limit: 2319)\n     Memory: 34.0M\n     CGroup: \/system.slice\/sssd.service\n             \u251c\u25007004 \/usr\/sbin\/sssd -i --logger=files\n             \u251c\u25007020 \/usr\/libexec\/sssd\/sssd_be --domain default --uid 0 --gid 0 --logger=files\n             \u251c\u25007021 \/usr\/libexec\/sssd\/sssd_nss --uid 0 --gid 0 --logger=files\n             \u2514\u25007022 \/usr\/libexec\/sssd\/sssd_pam --uid 0 --gid 0 --logger=files\n\nMay 08 11:38:20 koromicha systemd[1]: Starting System Security Services Daemon...\nMay 08 11:38:20 koromicha sssd[7004]: Starting up\nMay 08 11:38:21 koromicha sssd[be[7020]: Starting up\nMay 08 11:38:21 koromicha sssd[7021]: Starting up\nMay 08 11:38:21 koromicha sssd[7022]: Starting up\nMay 08 11:38:21 koromicha systemd[1]: Started System Security Services Daemon.\n<\/code><\/pre>\n\n\n\n<p>Enable SSSD to run on system boot;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl enable sssd<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure Auto-Home Directory Creation<\/h3>\n\n\n\n<p>To enable automatic creation of user\u2019s home directory on first login, you need to configure the PAM modules (<code>pam_mkhomedir.so<\/code>) as shown below.<\/p>\n\n\n\n<p>Open the&nbsp;<code>\/etc\/pam.d\/common-session<\/code>&nbsp;configuration file and edit is ad follows;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/pam.d\/common-session<\/code><\/pre>\n\n\n\n<p>Add the line below just below the line,&nbsp;<code>session optional pam_sss.so<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>session required        pam_mkhomedir.so skel=\/etc\/skel\/ umask=0022<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>...\n# The pam_umask module will set the umask according to the system default in\n# \/etc\/login.defs and user settings, solving the problem of different\n# umask settings with different shells, display managers, remote sessions etc.\n# See \"man pam_umask\".\nsession optional                        pam_umask.so\n# and here are more per-package modules (the \"Additional\" block)\nsession required        pam_unix.so\nsession optional                        pam_sss.so\n<strong>session required        pam_mkhomedir.so skel=\/etc\/skel\/ umask=0022<\/strong>\nsession optional        pam_systemd.so\n# end of pam-auth-update config\n...\n<\/code><\/pre>\n\n\n\n<p>Save and exit the configuration file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Verify SSSD OpenLDAP authentication<\/h3>\n\n\n\n<p>The installation and configuration of SSSD is done. To verify that you can login, try to authenticate against your LDAP server.<\/p>\n\n\n\n<p>In this guide, we have two users, <code>janedoe<\/code> and <code>johndoe<\/code>, created on our OpenLDAP Server for demo purposes.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ldapsearch -H ldapi:\/\/\/ -Y EXTERNAL -b \"ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\" dn -LLL -Q<\/code><\/pre>\n\n\n\n<p>The command above is ran on OpenLDAP server and the output is;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dn: ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\n\n<strong>dn: uid=janedoe,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\n\ndn: uid=johndoe,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com<\/strong><\/code><\/pre>\n\n\n\n<p>On the Ubuntu 20.04 ldap client,  these information about the users above should now be printable.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>root@ubuntu20:~# <strong>id johndoe<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>uid=10000(johndoe) gid=10000(johndoe) groups=10000(johndoe)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>root@ubuntu20:~# <strong>id janedoe<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>uid=10010(janedoe) gid=10010(janedoe) groups=10010(janedoe)<\/code><\/pre>\n\n\n\n<p>To demo the SSSD LDAP authentication, we will use both SSH and GUI based authentication;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Verify SSH Authentication via OpenLDAP SSSD<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ssh johndoe@ubuntu20<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\nThe authenticity of host 'ubuntu20 (192.168.58.19)' can't be established.\nECDSA key fingerprint is SHA256:gN94vPFvyZ3Rdeb\/+7R+0QJy9S4MdWmgJyEShIG9YgE.\nAre you sure you want to continue connecting (yes\/no)? yes\nWarning: Permanently added 'ubuntu20' (ECDSA) to the list of known hosts.\njohndoe@ubuntu20's password: \nCreating directory '\/home\/johndoe'.\nWelcome to Ubuntu 20.04 LTS (GNU\/Linux 5.4.0-29-generic x86_64)\n\n * Documentation:  https:\/\/help.ubuntu.com\n * Management:     https:\/\/landscape.canonical.com\n * Support:        https:\/\/ubuntu.com\/advantage\n\n * Ubuntu 20.04 LTS is out, raising the bar on performance, security,\n   and optimisation for Intel, AMD, Nvidia, ARM64 and Z15 as well as\n   AWS, Azure and Google Cloud.\n\n     https:\/\/ubuntu.com\/blog\/ubuntu-20-04-lts-arrives\n\n\n13 updates can be installed immediately.\n9 of these updates are security updates.\nTo see these additional updates run: apt list --upgradable\n\n\nThe programs included with the Ubuntu system are free software;\nthe exact distribution terms for each program are described in the\nindividual files in \/usr\/share\/doc\/*\/copyright.\n\nUbuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by\napplicable law.\n\njohndoe@ubuntu20:~$\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Verify GUI authentication via OpenLDAP SSSD<\/h4>\n\n\n\n<p>Reboot your Ubuntu 20.04 desktop after SSSD setup and and verify authentication.<\/p>\n\n\n\n<p>Once it boots, on the GDM login interface, click <strong>Not listed<\/strong> to enter your OpenLDAP username and password.<\/p>\n\n\n\n<p>We logged in on GUI as a different LDAP user, <strong>janedoe<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"724\" height=\"489\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2020\/05\/openldap-sssd-gui-auth.png\" alt=\"Configure SSSD for LDAP Authentication on Ubuntu 20.04\" class=\"wp-image-5841\" title=\"\"><\/figure><\/div>\n\n\n<p>Upon successful login, you land on Ubuntu 20.04 desktop.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1356\" height=\"671\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2020\/05\/sssd-gui-auth.png\" alt=\"\n\" class=\"wp-image-5842\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2020\/05\/sssd-gui-auth.png?v=1588939370 1356w, https:\/\/kifarunix.com\/wp-content\/uploads\/2020\/05\/sssd-gui-auth-768x380.png?v=1588939370 768w\" sizes=\"(max-width: 1356px) 100vw, 1356px\" \/><\/figure>\n\n\n\n<p>And there you go. You have successfully installed and configured SSSD for LDAP Authentication on Ubuntu 20.04.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Related Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/configure-sssd-for-openldap-authentication-on-ubuntu-18-04\/\" target=\"_blank\" rel=\"noreferrer noopener\">Configure SSSD for OpenLDAP Authentication on Ubuntu 18.04<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/kifarunix.com\/install-phpldapadmin-on-centos-8\/\" target=\"_blank\">Install phpLDAPadmin on CentOS 8<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/kifarunix.com\/configure-owncloud-openldap-authentication\/\" target=\"_blank\">Configure ownCloud OpenLDAP Authentication<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/kifarunix.com\/configure-openldap-host-based-authentication\/\" target=\"_blank\">Configure OpenLDAP Host Based Authentication<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/kifarunix.com\/how-to-create-openldap-member-groups\/\" target=\"_blank\">How to Create OpenLDAP Member Groups<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide will take you through how to install and configure SSSD for LDAP authentication on Ubuntu 20.04. SSSD (System Security Services Daemon) is a<\/p>\n","protected":false},"author":3,"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":[1585,1583,1584,1270,1271],"class_list":["post-5838","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","category-directory-server","category-openldap","tag-configure-sssd-on-ubuntu-20-04","tag-install-sssd-ubuntu-20-04","tag-setup-sssd-on-ubuntu-20-04","tag-sssd-openldap","tag-sssd-openldap-authentication","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\/5838"}],"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\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=5838"}],"version-history":[{"count":15,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/5838\/revisions"}],"predecessor-version":[{"id":21391,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/5838\/revisions\/21391"}],"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=5838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=5838"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=5838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}