<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shibani Shankar Dash</title>
    <description>The latest articles on DEV Community by Shibani Shankar Dash (@ssd71).</description>
    <link>https://dev.to/ssd71</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F301024%2F69f6a9be-1a53-435a-9db7-e257673e849a.jpeg</url>
      <title>DEV Community: Shibani Shankar Dash</title>
      <link>https://dev.to/ssd71</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ssd71"/>
    <language>en</language>
    <item>
      <title>PAM and Using Google Authenticator on Fedora</title>
      <dc:creator>Shibani Shankar Dash</dc:creator>
      <pubDate>Wed, 01 Jan 2020 05:50:34 +0000</pubDate>
      <link>https://dev.to/ssd71/pam-and-using-google-authenticator-on-fedora-2plh</link>
      <guid>https://dev.to/ssd71/pam-and-using-google-authenticator-on-fedora-2plh</guid>
      <description>&lt;p&gt;PAM(Pluggable Authentication Modules) has been on my mind lately. I've been trying to make heads and tails of it all since last week. I decided to try out a 3rd party module to get some context. So I tried plugging in the Google Authenticator module to see what it did.&lt;/p&gt;

&lt;p&gt;PAM or Pluggable Authentication Modules are a modular way of securing  parts of a Linux system. It was created by Oracle for the Solaris  Operating System but now has become a staple for Linux. The sheer  extensibility of the PAM system means that you can log in/authenticate  with any valid mechanism. Provided there exists a module that can support  it. To quote &lt;a href="https://www.aplawrence.com/Basics/understandingpam.html"&gt;this&lt;/a&gt; excellent article: "should someone invent a device that can read your brain waves and determine ill intent, all we need is a PAM module that can use that device". Now &lt;em&gt;that&lt;/em&gt; is cool.&lt;/p&gt;

&lt;p&gt;The first step is to install google-authenticator. Which you can do from your distro's repositories. I have Fedora so I did:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;dnf &lt;span class="nb"&gt;install &lt;/span&gt;google-authenticator
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now install the Google Authenticator for Android or FreeOTP for iOS. This application will be used to generate verification codes.&lt;/p&gt;

&lt;p&gt;Next we have to set up google-authenticator. To do this run &lt;code&gt;google-authenticator&lt;/code&gt; on a terminal. You will be guided through the entire setup. After you have finished configuring it, you will be provided a QR code which you can scan with the Google Authenticator on Android or FreeOTP on iOS. It will also give you a code that you can enter on the app if you cannot scan the QR code right now. There will also be some emergency codes that you should store &lt;em&gt;very&lt;/em&gt; carefully. These will come in handy when you have lost your phone or uninstalled the app.&lt;/p&gt;

&lt;p&gt;Next we have to edit the PAM configuration file for the SSH Daemon. Since we installed a third party PAM module, we have to list it in it's PAM configuration for sshd to use it.&lt;/p&gt;

&lt;p&gt;For Fedora, this configuration file was in /etc/pam.d, open the sshd file for editing, and comment out the line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;auth       substack     password-auth
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and add the following line at the bottom:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;auth       sufficient   pam_google_authenticator.so secret=~/.ssh/.google_authenticator
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The last line does two things. First it says to use the module &lt;code&gt;pam_google_authenticator.so&lt;/code&gt; for authentication. Second, make it so that completing this alone will be enough to auth someone through PAM. The extra argument should be &lt;strong&gt;ignored if you are not using Fedora&lt;/strong&gt;. What this does is tell the module to store it's files at a non-standard location. This is done to appease SELinux. If not done, SELinux denies access to these files during authentication. This results in failed authentication regardless of whether the verification code is valid. If you don't know what SELinux is, google it. It's awesome.&lt;/p&gt;

&lt;p&gt;Now, if you did supply the extra arguments then move the .google_authenticator directory from your home directory to the .ssh directory. Then, restore the SELinux context of the files using &lt;code&gt;restorecon -Rv ~/.ssh/&lt;/code&gt;. This step ensures that PAM module has access to the it's configuration files.&lt;/p&gt;

&lt;p&gt;After that, we edit the /etc/ssh/sshd_config file to tell sshd to use PAM. What we need to do is change the following lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PasswordAuthentication no # disable password based auth (optional)
ChallengeResponseAuthentication yes # enable pam based auth

# Add the following line at the bottom
AuthenticationMethods keyboard-interactive
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The last line specifies the authentication methods that a user must complete to be granted access. This setup only requires keyboard-interactive(which just means PAM based auth) to be completed.  Realistically, you would use SSH keys in conjunction with this setup for added security. To use SSH keys with it, change the last line to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AuthenticationMethods publickey,keyboard-interactive
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now, restart the sshd service: &lt;code&gt;sudo systemctl restart sshd.service&lt;/code&gt;. Try and SSH into your new setup!&lt;/p&gt;

</description>
      <category>linux</category>
      <category>ssh</category>
      <category>security</category>
    </item>
  </channel>
</rss>
