Giter Club home page Giter Club logo

2fauthmanjaro's Introduction

Two Factor Authentication on Manjaro (with Google-Authenticator)

Setup Google-Authenticator Two-Factor-Authentification on Manjaro Linux. Even tough the Application was initially developed by Google it does no phone home for providing the two-factor auth service. The application supports the HMAC-Based One-time Password (HOTP) algorithm specified in RFC 4226 and the Time-based One-time Password (TOTP) algorithm specified in RFC 6238. The Source-Code for the Linux Project can be found at github/google-authenticator.

Further reading

Requirements

  1. Manjaro Linux
  2. Smartphone (Android / iPhone )

Important Notes

This tutorial does not cover using Two-Factor-Authentification on systems with “home folder encryption” that encrypted your entire home directory until you enter your password. Specifically, this uses ecryptfs. However, because the PAM software depends on a Google Authenticator file stored in your home directory by default, the encryption interferes with the PAM reading the file unless you ensure it’s available in unencrypted form to the system before you log in. Consult the README for more information on avoiding this problem if your’e still using the deprecated home directory encryption options. However Full-Disk-Encryption is a non issue, because the filesystem is decrypted at the point the pam module authentificates the user and it just works normally.

It is highly recommendet to install a ntp client on your system, because the whole key-generation depends on synchronized time. If you phone and PC time differe by to much the generated codes won't work. manjaro-wiki

Install

  • Manjaro
    • pacman -S ntp
    • yaourt libpam-google-authenticator
  • Phone
    • Android (PlayStore): FreeOTP
    • IOS (AppStore): FreeOTP

Create Your Authentication Keys

You’ll now need to create a secret authentication key and enter it into the Google Authenticator app (or a similar) app on your phone. First, log in as your user account on your Linux system. Open a terminal window and run the google-authenticator command. Type y and follow the prompts here. This will create a special file in the current user account’s directory with the Google Authenticator information.

You’ll also be walked through the process of getting that two-factor verification code into a Google Authenticator or similar TOTP app on your smartphone. Your system can generate a QR code you can scan, or you can type it in manually.

google-authenticator command

Important: Be sure to note down your emergency scratch codes, which you can use to log in with if you lose your phone. Or print the output of the command to a peace of paper and store it in a secure place. You can use the QR-Code if you have lost your phone to setup you app on an other phone again.

Warning: Do not share any of the given Information of the command with a third party, anyone with the shown codes is able to login to your system if they get hold of your regular password.

Go through this process for each user account that uses your computer. For example, if you’re the only person who uses your computer, you can just do it once on your normal user account. If you have someone else who uses your computer, you’ll want to have them sign into their own account and generate an appropriate two-factor code for their own account so they’ll be able to log in.

phone app

Example of generates One-Time passwords:

Remote Login

Warning: If you do all configuration via SSH do not close the session before you tested that everything is working, else you may lock yourself out. Furthermore consider generating the key file before activating the PAM.

Usually one demands two-pass authentication only for remote login. The corresponding PAM configuration file is /etc/pam.d/system-remote-login. To enter both, your unix password and your OTP, add pam_google_authenticator.so above the auth include system-login lines to /etc/pam.d/system-remote-login:

#%PAM-1.0

auth      required  pam_google_authenticator.so
auth      include   system-login
account   include   system-login
password  include   system-login
session   include   system-login

This will ask for the OTP before prompting for your Unix password. Changing the order of the two auth modules will reverse this order.

Warning: Only users that have generated a secret key file (see below) will be allowed to log in using eg. SSH.

To allow login with either the OTP or your Unix password use:

auth required pam_google_authenticator.so nullok

The “nullok” bit at the end tells the system to let a user log in even if they haven’t run the google-authenticator command to set up two-factor authentication. If they have set it up, they’ll have to enter a time-based code — otherwise they won’t.

Enable challenge-response authentication for SSH in /etc/ssh/sshd_config:

ChallengeResponseAuthentication yes

Finally, reload the sshd service. systemctl sshd reload

Warning: OpenSSH will ignore all of this if you are authenticating with a SSH-key pair and have disabled password logins. However, as of OpenSSH 6.2, you can add AuthenticationMethods to allow both: two-factor and key-based authentication. (archwiki)

Authenticate the user on both a publickey and the user authentication as required by your PAM setup in /etc/ssh/sshd_config:

AuthenticationMethods publickey,keyboard-interactive:pam

Graphical-Logins (lightdm)

Warning: These specific steps will only work if your Linux distribution and desktop use the LightDM login manager.

Add the following line to the file /etc/pam.d/lightdm:

auth required pam_google_authenticator.so nullok

The “nullok” bit at the end tells the system to let a user log in even if they haven’t run the google-authenticator command to set up two-factor authentication. If they have set it up, they’ll have to enter a time-based code — otherwise they won’t. Remove the “nullok” and user accounts who haven’t set up a Google Authenticator code just won’t be able to log in graphically.

sudo vim /etc/pam.d/lightdm

#%PAM-1.0
auth        include     system-login
auth        required    pam_google_authenticator.so
-auth       optional    pam_gnome_keyring.so
account     include     system-login
password    include     system-login
session     include     system-login
-session    optional    pam_gnome_keyring.so auto_start

At the next Login you are greeted with your default Login-Mask, just enter your regular password:

password login

After pressing the Enter key or pushing the Log In button you will be prompted for the One-Time password regardless if your password was correct or not before:

verification code

After entering the Verification Code generated on your phone and pressing the Enter key or pushing the Log In button you are logged in.

Local Virtual Terminal (eg. ALT+F2)

Securing SSH and the Graphical-Login still leaves us open to Logins via the Virtual Terminal eg. ALT+F2 on the Graphical Login-Mask. To secure this login as well with two-facto authentification we need to edit the /etc/pam.d/login file and add pam_google_authenticator.so below system-local-login:

#%PAM-1.0

auth       required     pam_securetty.so
auth       requisite    pam_nologin.so
auth       include      system-local-login
auth       required     pam_google_authenticator.so
account    include      system-local-login
session    include      system-local-login

Example local Login ALT+F2:

verification code

2fauthmanjaro's People

Contributors

t4skforce avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.