{"id":977,"date":"2019-12-07T16:55:01","date_gmt":"2019-12-07T21:55:01","guid":{"rendered":"https:\/\/www.bu.edu\/engit\/?page_id=977"},"modified":"2026-07-16T15:05:33","modified_gmt":"2026-07-16T19:05:33","slug":"authentication","status":"publish","type":"page","link":"https:\/\/www.bu.edu\/engit\/knowledge-base\/linux\/unbuntu\/authentication\/","title":{"rendered":"AD Authentication"},"content":{"rendered":"<p class=\"line874\">Before starting, make sure your hostname is less than 15 characters long and unique. Picking a hostname that is used, such as &#8220;computer&#8221; or &#8220;ubuntu&#8221;, will result in the join failing or breaking someone elses join. Log in with a user account that has sudo privileges.<\/p>\n<h2 id=\"ConfigureRealm\">Configure Hostname<\/h2>\n<p>Set the example hostname &#8216;foo&#8217;<\/p>\n<pre class=\"darkSnippet\">$ sudo hostnamectl set-hostname foo\r\n<\/pre>\n<p>Edit \/etc\/hosts, with these entries for &#8216;foo&#8217;:<\/p>\n<pre class=\"darkSnippet\">127.0.0.1         localhost\r\n127.0.1.1         foo.ad.bu.edu foo.bu.edu foo\r\n# Only use if there's a DNS entry for foo.bu.edu (e.g. a DHCP reservation or static IP)     \r\n<\/pre>\n<p>and test hostname and FQDN are correct<\/p>\n<pre class=\"darkSnippet\">$ hostname\r\nfoo<br>\r\n$ hostname -f\r\nfoo.ad.bu.edu\r\n<\/pre>\n<h2 id=\"ConfigureRealm\">Configure Realm<\/h2>\n<p class=\"line874\">Create a file called \/etc\/realmd.conf, with these contents:<\/p>\n<pre class=\"darkSnippet\">[users]\r\ndefault-home = \/home\/%U\r\ndefault-shell = \/bin\/bash\r\n \r\n[active-directory]\r\ndefault-client = sssd\r\nos-name = Ubuntu\r\nos-version = 26.04\r\n \r\n[service]\r\n# Set this to no to disable automatic installation of packages via package-kit.\r\n#automatic-install = no\r\n \r\n[ad.bu.edu]\r\nfully-qualified-names = no\r\nautomatic-id-mapping = no\r\nuser-principal = yes\r\nmanage-system = yes\r\n#computer-name = HOSTNAME # Commented out because we'll add it to the realm request\r\ncomputer-ou = OU=Linux,OU=ENG,DC=ad,DC=bu,DC=edu<\/pre>\n<h2 id=\"ConfigureKerberos\">Configure Kerberos<\/h2>\n<p>Copy the krb5.conf file to \/etc\/krb5.conf. This will place the Kerberos configuration setup for the BU AD into the proper place.<\/p>\n<p class=\"line874\">Here&#8217;s the file:<\/p>\n<pre class=\"darkSnippet\">[logging]\r\n default = FILE:\/var\/log\/krb5libs.log\r\n kdc = FILE:\/var\/log\/krb5kdc.log\r\n admin_server = FILE:\/var\/log\/kadmind.log\r\n\r\n# Default settings for kerberos.\r\n# \r\n# rdns = false is essential if reverse DNS queries don't resolve correctly\r\n# (which for active directory, they don't!)  According to the krb5.conf docs,\r\n# this is actually *more* secure than the default reverse DNS behavior.  But,\r\n# it means we will need to use the correct fully-qualified domain names\r\n# consistently for kerberized stuff to work.\r\n# See also: the \"-l\" option to rpc.gssd.\r\n\r\n[libdefaults]\r\n default_realm = AD.BU.EDU\r\n dns_lookup_realm = false\r\n dns_lookup_kdc = false\r\n ticket_lifetime = 24h\r\n renew_lifetime = 7d\r\n forwardable = true\r\n rdns = false\r\n\r\n[realms]\r\n\r\n# The bu.edu kerberos realm, separate from active directory.\r\n# \r\n# We're not currently using this, but it's in the BU Linux config and available\r\n# if you specify user@bu.edu instead of letting it use the default realm.\r\n# Unlike with the active directory realm below, it doesn't look like there's\r\n# any unified setup in DNS for the KDC's, so each kdc is listed separately.\r\n# bu.edu = {\r\n#  kdc = kerberos1.bu.edu.\r\n#  kdc = kerberos2.bu.edu.\r\n#  kdc = kerberos3.bu.edu.\r\n#  admin_server = kerberos1.bu.edu.\r\n# }\r\n\r\n# The BU active directory realm.\r\n# \r\n# We could also explicitly list all the domain controllers here, but the domain\r\n# points to the whole set of ist-adc1.bu.edu -&gt; ist-adc5.bu.edu, so this is\r\n# really all that's needed.\r\n# NOTE ABOUT SSSD:\r\n# The sssd package adds plugins to the krb5 library in \/usr\/lib64\/krb5\/plugins\r\n# and one effect of this is that basic kerberos commands like kinit and kvno\r\n# are actually affected by SSSD's settings, in particular this cached KDC info:\r\n# \/var\/lib\/sss\/pubconf\/kdcinfo.AD.BU.EDU\r\n# If you change the kdc settings here, also delete that cache and check the\r\n# krb5_server setting in \/etc\/sssd\/sssd.conf.\r\n\r\n AD.BU.EDU = {\r\n  kdc = ad.bu.edu.\r\n  admin_server = ad.bu.edu.\r\n}\r\n\r\n# Mapping of domains to kerberos realms.\r\n# \r\n# These entries will at least map any reference to an active directory hostname\r\n# to the realm, and if we wanted we could also point bu.edu to that as well.\r\n# As per the docs on krb5.conf, an entry starting with a period is for a whole\r\n# domain, while one without specifies an actual host.\r\n\r\n[domain_realm]\r\n .ad.bu.edu = AD.BU.EDU\r\n ad.bu.edu = AD.BU.EDU\r\n\r\n[appdefaults]\r\n pam = {\r\n  minimum_uid = 3000\r\n}<\/pre>\n<h2 id=\"Installpackages\">Install Packages<\/h2>\n<pre class=\"darkSnippet\">$ sudo apt install -y realmd sssd sssd-tools libnss-sss libpam-sss krb5-user adcli samba-common-bin<\/pre>\n<h2>Set DNS Search Domains<\/h2>\n<p>This used to be set in the NetworkManager GUI , but was removed in recent versions. Now use wither the old GUI:<\/p>\n<pre class=\"darkSnippet\">$ sudo nm-connection-editor\r\n<\/pre>\n<p>In the <strong>IPv4 Settings<\/strong> tab set the <strong>search domains<\/strong> to &#8220;ad.bu.edu, bu.edu&#8221;.<\/p>\n<p>Then restart the NetworkManager service<\/p>\n<pre class=\"darkSnippet\">$ sudo systemctl restart NetworkManager<\/pre>\n<p>Or set it via the command line<\/p>\n<pre class=\"darkSnippet\"># nmcli c show\r\n# nmcli c modify \"Wired connection 1\" ipv4.dns-search \"ad.bu.edu, bu.edu\"\r\n# nmcli c down \"Wired connection 1\" &amp;&amp; nmcli c up \"Wired connection 1\"<\/pre>\n<p>More with <a href=\"https:\/\/askubuntu.com\/questions\/1068467\/how-to-set-domain-search-on-ubuntu-18-04\">this link<\/a>.<\/p>\n<h2 id=\"SynctimewiththeADdomain\">Sync time with the AD domain<\/h2>\n<p class=\"line874\">Kerberos only works if the date and time of the computer to join the AD and the AD are the same. Ubuntu and many other distrobution use chrony to manage NTP.<\/p>\n<p>Add the following to \/etc\/chrony\/sources.d\/ubuntu-ntp-pools.sources :<\/p>\n<pre class=\"darkSnippet\">\r\n# Primary Time Source (Active Directory Domain Controllers)\r\nserver ad.bu.edu iburst prefer\r\n\r\n# Boston University Fallback NTP Servers\r\n# This pool is managed be the F5 and not DNS alone\r\n# so if a NTP hosts is down the F5 serves another in the pool\r\nserver ntp-pool.bu.edu iburst\r\n\r\n# Boston University old Fallback NTP Servers\r\n#server ntp1.bu.edu iburst\r\n#server ntp2.bu.edu iburst\r\n#server ntp3.bu.edu iburst\r\n<\/pre>\n<p>Comment out ntp-bootstrap.ubuntu.com<\/p>\n<pre class=\"darkSnippet\">\r\n#pool ntp-bootstrap.ubuntu.com iburst maxsources 1 nts certset 1\r\n<\/pre>\n<p class=\"line874\">To sync the time on the localhost, run:<\/p>\n<pre class=\"darkSnippet\">\r\n$ sudo timedatectl set-timezone  America\/New_York\r\n$ sudo chronyc reload sources\r\n$ sudo chronyc sources -v<\/pre>\n<p class=\"line874\">Check it worked with the following:<\/p>\n<pre class=\"darkSnippet\">$ timedatectl status<\/pre>\n<h2 id=\"UsePamtomakeahomedirectory\">Use Pam to make Home Directories<\/h2>\n<p class=\"line874\">This can be done two ways.<\/p>\n<h3>i. Using the pam-auth-update tool: Run the command to launch pam-auth-update:<\/h3>\n<pre class=\"darkSnippet\">$ sudo pam-auth-update<\/pre>\n<p class=\"line874\">A window will open. Check the &#8220;Create home directory on login&#8221; box. You&#8217;ll need to use the down arrow.<\/p>\n<h3>ii. Through command line:<\/h3>\n<p class=\"line874\">Edit \/etc\/pam.d\/common-session, and add this line directly after session required pam_unix.so:<\/p>\n<pre class=\"darkSnippet\">session required pam_mkhomedir.so skel=\/etc\/skel\/ umask=0022<\/pre>\n<h2 id=\"Jointhedomain\">Join the domain<\/h2>\n<p class=\"line862\">Run the following command to join the example system to the AD realm in the Engineering OU:<\/p>\n<pre class=\"darkSnippet\">$ sudo realm join -v --computer-name=$(hostname -s) --user=&lt;username&gt;-adm ad.bu.edu\r\n<\/pre>\n<pre>Where &lt;hostname&gt; <hostname>is not the FQDM<\/hostname><\/pre>\n<h2>Configure SSSD<\/h2>\n<p class=\"line874\">Joining AD creates a file \/etc\/sssd\/sssd.conf. You need to configure SSSD, after editing it should look something like this:<\/p>\n<pre class=\"darkSnippet\">\r\n\r\n[sssd]\r\ndomains = ad.bu.edu\r\nconfig_file_version = 2\r\nservices = nss, pam\r\n\r\n[domain\/ad.bu.edu]\r\n# replace ldap_sasl_authid (below) with the\r\n# name generated in the original \/etc\/sssd\/sssd.conf\r\nldap_sasl_authid = my-hostname$\r\ndefault_shell = \/bin\/bash\r\nkrb5_store_password_if_offline = True\r\ncache_credentials = True\r\nkrb5_realm = AD.BU.EDU\r\nrealmd_tags = manages-system joined-with-adcli\r\nid_provider = ad\r\nfallback_homedir = \/home\/%u\r\nad_domain = ad.bu.edu\r\nuse_fully_qualified_names = False\r\nldap_id_mapping = False\r\n\r\n# Use UID and GID from Active Directory with BU-specific ID fields\r\n# note that this will change some day when IAM removes bu-ph-index-id-numeric\r\nldap_user_gecos = displayName\r\nldap_user_uid_number = bu-ph-index-id-numeric\r\nldap_user_gid_number = bu-ph-index-id-numeric\r\n\r\n# Make account name be just username, not \"username@domain\"\r\nfull_name_format = %1$s\r\n<\/pre>\n<p class=\"line874\">To restrict access, add one of these to the end of the sssd.conf file:<\/p>\n<pre class=\"darkSnippet\">### Restrict login access to specific accounts ###\r\n\r\naccess_provider = simple\r\nsimple_allow_groups = my-ad-groupname<\/pre>\n<ul>\n<li style=\"list-style-type: none;\">-or-<\/li>\n<\/ul>\n<pre class=\"darkSnippet\">### Restrict login access to specific accounts ###\r\n#access_provider = ad\r\n# Pick one of:\r\n\r\n# IS&amp;T\r\n#ad_access_filter = (bu-ph-deptid=51*)\r\n# ENG 24043\r\n#ad_access_filter = (bu-ph-deptid=24*)\r\n\r\n#ad_access_filter = (|(sAMAccountName=moe)(sAMAccountName=larry)(sAMAccountName=curly))\r\n#ad_access_filter = (|(manager=CN=smith,OU=People,DC=ad,DC=bu,DC=edu)(manager=CN=jones,OU=People,DC=ad,DC=bu,DC=edu))<\/pre>\n<h2 id=\"RestartSSSDasroottoimplementchanges\">Restart SSSD as root to implement changes<\/h2>\n<p class=\"line874\">Restart the service and clear the SSS cache:<\/p>\n<pre class=\"darkSnippet\">$ sudo systemctl restart sssd &amp;&amp; sss_cache -E<\/pre>\n<h2 id=\"ConfirmthejoinbyloggingintoAD\">Confirm the join by logging into AD<\/h2>\n<p class=\"line874\">Install the OpenSSH server:<\/p>\n<pre class=\"darkSnippet\">$ sudo apt -y install openssh-server\r\n<\/pre>\n<p>And setup a firewall restricting access to BU IP Space<\/p>\n<pre class=\"darkSnippet\">$ sudo ufw default deny incoming\r\n$ sudo ufw default allow outgoing\r\n$ sudo ufw allow from 128.197.0.0\/16 to any port 22\r\n$ sudo ufw allow from 10.0.0.0\/8 to any port 22\r\n$ sudo ufw allow from 168.122.0.0\/16 to any port 22\r\n$ sudo ufw enable\r\n<\/pre>\n<p class=\"line874\">Now test login<\/p>\n<pre class=\"darkSnippet\">$ ssh kerberos_username@localhost<\/pre>\n<p class=\"line874\">This should prompt for your Kerberos password and should successfully log into AD.<\/p>\n<p>&nbsp;<\/p>\n<h2>Ubuntu Server 22.04<\/h2>\n<p data-sourcepos=\"1:1-1:320\">In Ubuntu 22.04, SSH prioritizes public key authentication over password authentication. When you join an Ubuntu server to Active Directory, it doesn&#8217;t automatically configure SSH to allow password authentication for AD users. Here&#8217;s a breakdown of the issue and how to resolve it:<\/p>\n<p data-sourcepos=\"3:1-3:29\"><strong>Understanding the Problem<\/strong><\/p>\n<ul>\n<li data-sourcepos=\"5:1-5:251\"><strong>Public Key Authentication:<\/strong> SSH tries to authenticate users based on cryptographic keys. If you haven&#8217;t set up key-based authentication for your AD users on the Ubuntu server, this method will fail, resulting in &#8220;Permission denied (publickey).&#8221;<\/li>\n<li data-sourcepos=\"6:1-7:0\"><strong>Password Authentication:<\/strong> Even though your AD users can log in via the console (using their passwords), SSH might be configured to disallow password authentication, especially if <code>PasswordAuthentication no<\/code> is set in the SSH server configuration.<\/li>\n<li data-sourcepos=\"11:1-12:0\">\n<p data-sourcepos=\"11:5-11:296\"><strong>Locate the Correct File:<\/strong> Check the contents of <code>\/etc\/ssh\/sshd_config<\/code> for an <code>Include<\/code> directive. It might point to files within <code>\/etc\/ssh\/sshd_config.d\/<\/code>. Alternatively, check the files in <code>\/etc\/ssh\/sshd_config.d\/<\/code> directly to see which one contains the <code>PasswordAuthentication<\/code> setting.<\/p>\n<\/li>\n<li data-sourcepos=\"13:1-14:0\">\n<p data-sourcepos=\"13:5-13:129\"><strong>Edit the File:<\/strong> Use <code>sudo nano \/etc\/ssh\/sshd_config.d\/50-cloud-init.conf<\/code> (or the appropriate file name) to edit the file.<\/p>\n<\/li>\n<li data-sourcepos=\"15:1-16:0\">\n<p data-sourcepos=\"15:5-15:173\"><strong>Set <code>PasswordAuthentication yes<\/code>:<\/strong> Ensure that the <code>PasswordAuthentication<\/code> directive is set to <code>yes<\/code>. If the line is commented out (preceded by a <code>#<\/code>), uncomment it.<\/p>\n<\/li>\n<li data-sourcepos=\"17:1-22:0\">\n<p data-sourcepos=\"17:5-17:71\"><strong>Restart SSH:<\/strong> After making the changes, restart the SSH service:<\/p>\n<p><response-element class=\"\" ng-version=\"0.0.0-PLACEHOLDER\"><code-block _nghost-ng-c1496191289=\"\" class=\"ng-tns-c1496191289-40 ng-star-inserted\"><\/code-block><\/response-element><\/p>\n<div _ngcontent-ng-c1496191289=\"\" class=\"code-block ng-tns-c1496191289-40 ng-trigger ng-trigger-codeBlockRevealAnimation\" jslog=\"223238;track:impression;BardVeMetadataKey:[[&quot;r_93864b38e4c7fbfd&quot;,&quot;c_8aab0b3c9666f85c&quot;,null,&quot;rc_c7207ab7ef758a1a&quot;,null,null,&quot;en&quot;,null,1,null,null,1,0]]\">\n<div _ngcontent-ng-c1496191289=\"\" class=\"ng-tns-c1496191289-40 formatted-code-block-internal-container\">\n<div _ngcontent-ng-c1496191289=\"\" class=\"animated-opacity ng-tns-c1496191289-40\">\n<pre _ngcontent-ng-c1496191289=\"\" class=\"ng-tns-c1496191289-40\"><code _ngcontent-ng-c1496191289=\"\" role=\"text\" data-test-id=\"code-content\" class=\"code-container ng-tns-c1496191289-40 formatted\" data-sourcepos=\"19:5-21:30\">sudo systemctl restart ssh\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>&nbsp;<\/li>\n<li data-sourcepos=\"23:1-24:0\">\n<p data-sourcepos=\"23:5-23:432\"><strong>Cloud-Init Considerations:<\/strong> If <code>cloud-init<\/code> is actively managing the system, it might revert your changes on the next reboot or instance restart. To prevent this, you&#8217;ll need to configure <code>cloud-init<\/code> itself. This can be done by modifying the cloud-init configuration files (usually in <code>\/etc\/cloud\/cloud.cfg.d\/<\/code>) or by using cloud-init modules to manage SSH settings. The exact method depends on your cloud provider or setup.<\/p>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2 class=\"line862\">CentOS<\/h2>\n<p class=\"line862\">For instructions on joining CentOS 7 &amp; 8 systems to AD, see the BU IS&amp;T page <a class=\"https\" href=\"https:\/\/www.bu.edu\/tech\/services\/security\/iam\/directory\/ad\/linux\/\">here<\/a>.<\/p>\n<h1 id=\"AddingUsers\">Adding Users<\/h1>\n<ul>\n<li>When you add users that will authenticate with kerberos, they should have the same UID as their BU account. If you don&#8217;t know the UID, you can find it in the <a class=\"http\" href=\"http:\/\/www.bu.edu\/directory\/\">BU Directory<\/a>. The UID is the numeric part of the <em>Index ID<\/em><\/li>\n<li>If you have already made a user with the correct name but incorrect UID, you need to change the UID (and hence all files associated with that UID) to the correct number. Replace $OLD_UID, and $NEW_UID with the appropriate numbers in the following commands.<\/li>\n<li>Change the UID (this will automatically change files in the home directory to the new UID):\n<pre class=\"darkSnippet\">sudo usermod -u $NEW_UID user_name<\/pre>\n<\/li>\n<li class=\"gap\">If the user owns files outside of their home directory, you may want to search them out and change the UID.\n<pre class=\"darkSnippet\">find \/tmp -uid $OLD_UID -exec chown $NEW_UID {} \\;<\/pre>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Before starting, make sure your hostname is less than 15 characters long and unique. Picking a hostname that is used, such as &#8220;computer&#8221; or &#8220;ubuntu&#8221;, will result in the join failing or breaking someone elses join. Log in with a user account that has sudo privileges. Configure Hostname Set the example hostname &#8216;foo&#8217; $ sudo [&hellip;]<\/p>\n","protected":false},"author":1470,"featured_media":0,"parent":339,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/www.bu.edu\/engit\/wp-json\/wp\/v2\/pages\/977"}],"collection":[{"href":"https:\/\/www.bu.edu\/engit\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.bu.edu\/engit\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.bu.edu\/engit\/wp-json\/wp\/v2\/users\/1470"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bu.edu\/engit\/wp-json\/wp\/v2\/comments?post=977"}],"version-history":[{"count":37,"href":"https:\/\/www.bu.edu\/engit\/wp-json\/wp\/v2\/pages\/977\/revisions"}],"predecessor-version":[{"id":2694,"href":"https:\/\/www.bu.edu\/engit\/wp-json\/wp\/v2\/pages\/977\/revisions\/2694"}],"up":[{"embeddable":true,"href":"https:\/\/www.bu.edu\/engit\/wp-json\/wp\/v2\/pages\/339"}],"wp:attachment":[{"href":"https:\/\/www.bu.edu\/engit\/wp-json\/wp\/v2\/media?parent=977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}