<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>22.04 on Andrew Beaton</title>
    <link>https://andrewbeaton.net/tags/22.04/</link>
    <description>Recent content in 22.04 on Andrew Beaton</description>
    <image>
      <title>Andrew Beaton</title>
      <url>https://andrewbeaton.net/me.jpeg</url>
      <link>https://andrewbeaton.net/me.jpeg</link>
    </image>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Sun, 04 Jun 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://andrewbeaton.net/tags/22.04/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Setting Up Multi-Factor Authentication (MFA) on Ubuntu 22.04</title>
      <link>https://andrewbeaton.net/posts/2023/06/ubuntu-mfa/</link>
      <pubDate>Sun, 04 Jun 2023 00:00:00 +0000</pubDate>
      
      <guid>https://andrewbeaton.net/posts/2023/06/ubuntu-mfa/</guid>
      <description>Setting Up Multi-Factor Authentication (MFA) on Ubuntu 22.04</description>
      <content:encoded><![CDATA[<h2 id="introduction">Introduction</h2>
<p>These days, securing your systems and data is of great importance.</p>
<p>One powerful security measure is Multi-Factor Authentication (MFA), which adds an extra layer of protection by requiring users to provide additional credentials beyond just a password.</p>
<p>In this post, I will guide you through the process of setting up MFA on Ubuntu 22.04, enhancing the security of your system.</p>
<h2 id="prerequisites">Prerequisites</h2>
<p>Before we begin, make sure you have the following:</p>
<ul>
<li>A user account with sudo privileges.</li>
<li>Ubuntu 22.04 installed (Not tested on other versions).</li>
<li>An MFA authenticator app, such as Google Authenticator or Authy.</li>
</ul>
<h2 id="step-1-install-the-required-packages">Step 1: Install the Required Packages</h2>
<p>The first step is to install the necessary packages that will enable MFA on your Ubuntu system.</p>
<p>Open a terminal and run the following commands:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo apt update
</span></span><span style="display:flex;"><span>sudo apt install libpam-google-authenticator -y
</span></span></code></pre></div><p>These commands will update your package lists and install the <em>libpam-google-authenticator</em> package, which will be used to generate MFA codes.</p>
<h2 id="step-2-configure-mfa-for-a-user">Step 2: Configure MFA for a User</h2>
<p>Once the package is installed, you can configure MFA for a specific user account.</p>
<p>In the terminal, execute the following command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>google-authenticator
</span></span></code></pre></div><p>This command will initiate the setup process and present you with a series of questions.</p>
<p>You will be prompted to scan a QR code with an MFA authenticator app, such as Google Authenticator or Authy. Alternatively, you can enter the provided key manually into your authenticator app.</p>
<p>You will be asked if you want to update the <em>.google_authenticator</em> file. Press y and hit Enter to proceed.</p>
<p>You will be asked a series of questions. It is recommended to answer &lsquo;y&rsquo; for all the questions to enable the maximum level of security. These questions include options such as disallowing multiple uses of the same authentication token and enabling rate limiting.</p>
<p>Once you have completed the setup, you will be provided with backup codes.</p>
<p>It is crucial to store these backup codes in a secure location, as they can be used to access your account if you lose access to your MFA device.</p>
<h2 id="step-3-configure-ssh-to-use-mfa">Step 3: Configure SSH to Use MFA</h2>
<p>To enable MFA for SSH logins, you need to configure the SSH daemon to utilise MFA.</p>
<p>Open the SSH configuration file by running the following command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo nano /etc/pam.d/sshd
</span></span></code></pre></div><p>In the editor, add the following line at the top of the file:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-swift" data-lang="swift"><span style="display:flex;"><span>auth <span style="color:#66d9ef">required</span> pam_google_authenticator.so
</span></span></code></pre></div><p>Save the changes and exit the editor by pressing Ctrl + X, followed by Y, and then hitting Enter.</p>
<h2 id="step-4-restart-ssh-service">Step 4: Restart SSH Service</h2>
<p>To apply the changes made to the SSH configuration, you need to restart the SSH service.</p>
<p>Run the following command to restart SSH:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo systemctl restart sshd
</span></span></code></pre></div><h2 id="step-5-test-mfa">Step 5: Test MFA</h2>
<p>Now that MFA is set up, it&rsquo;s time to test if it&rsquo;s working as expected.</p>
<p>Open a new terminal window and attempt to SSH into your Ubuntu system using the user account you configured for MFA.</p>
<p>You should be prompted for your MFA verification code after entering your password.</p>
<h2 id="summary">Summary</h2>
<p>You have successfully set up Multi-Factor Authentication (MFA) on your Ubuntu 22.04 system.</p>
<p>By implementing MFA, you have significantly enhanced the security of your system and reduced the risk of unauthorised access.</p>
<p>Remember to keep your backup codes safe in case you need them.</p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
