Stay at Home!! Be Safe!! Take Care!!

For Any queries, please mail us at support@funoracleapps.com

Multi-Factor Authentication in Linux using Google Authenticator

No comments

Multi-Factor Authentication in Linux using Google Authenticator



I would setting up a multifactor authentication in my Centos 7 for a user Kevin for ssh connectivity.

1) Add the EPEL (Extra Packages for Enterprise Linux) repo.

sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

2) Install the google-autheticator

sudo yum install google-authenticator


3) Run the google autheticator app for the user for which we want to setup the MFA. Note secret key and Verification code will be shown which would be needed for setting up google Autheticator on Android/Iphone

google-authenticator

It will prompt you certain questions as below , Provide the mentioned values


[kevin@lcfs ~]$ google-authenticator

Do you want authentication tokens to be time-based (y/n) y
Warning: pasting the following URL into your browser exposes the OTP secret to Google:


Do you want me to update your "/home/kevin/.google_authenticator" file? (y/n) y

Do you want to disallow multiple uses of the same authentication
token? This restricts you to one login about every 30s, but it increases
your chances to notice or even prevent man-in-the-middle attacks (y/n) y

By default, a new token is generated every 30 seconds by the mobile app.
In order to compensate for possible time-skew between the client and the server,
we allow an extra token before and after the current time. This allows for a
time skew of up to 30 seconds between authentication server and client. If you
experience problems with poor time synchronization, you can increase the window
from its default size of 3 permitted codes (one previous code, the current
code, the next code) to 17 permitted codes (the 8 previous codes, the current
code, and the 8 next codes). This will permit for a time skew of up to 4 minutes
between client and server.
Do you want to do so? (y/n) n

If the computer that you are logging into isn't hardened against brute-force
login attempts, you can enable rate-limiting for the authentication module.
By default, this limits attackers to no more than 3 login attempts every 30s.
Do you want to enable rate-limiting? (y/n) y



4) Edit the PAM authetication moddule to use google authetication

sudo vi /etc/pam.d/sshd
Add the following line to the bottom of the file.

/etc/pam.d/sshd
. . .
# Used with polkit to reauthorize users in remote sessions
-session   optional     pam_reauthorize.so prepare
auth required pam_google_authenticator.so nullok

5) Edit the ssh configuration file to accept Authetication using MFA.

sudo vi /etc/ssh/sshd_config
Look for ChallengeResponseAuthentication lines. Comment out the no line and uncomment the no line.

/etc/ssh/sshd_config
. . .
# Change to no to disable s/key passwords
ChallengeResponseAuthentication yes
#ChallengeResponseAuthentication no

6) Restart sshd service
service sshd restart

7) Install the Google Autheticator App and configured using secrete key received from step 3.



8) Trying logging using user Kevin and verify.

himanshu@himanshu-ThinkPad-T430 ~ $ ssh kevin@lfcs.lab
Password: 
Verification code: 
Last login: Sat Apr 11 12:37:19 2020 from 192.168.56.1
[kevin@lcfs ~]$ exit

No comments :

Post a Comment