Multi-factor authentication has been one of the incredible things that security people love. An extra layer of protection that authorized person has, have or are. Now let’s get straight to the point on configuring two-factor authentication on CentOS 7.
- Let’s first install the additional repository called epel
 
sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
- Now let’s install google-authenticator
 
sudo yum install google-authenticator
- Once installed type following to start the setup
 
google-authenticator
- Some questions will be asked as follow
 
Do you want authentication tokens to be time-based (y/n) y
- Once you say yes. QR code will be displayed. Scan it using your favorite authenticator. And follow questions after this.
 
Do you want me to update your "/home/username/.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, tokens are good for 30 seconds. 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. If you experience problems with
poor time synchronization, you can increase the window from its default
size of +-1min (window size of 3) to about +-4min (window size of 17 acceptable tokens). 
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
- Now edit pam.d/sshd file to enable google authentication
 
sudo nano /etc/pam.d/sshd
- Add the following line at bottom of the file
 
. . .
# Used with polkit to reauthorize users in remote sessions
-session   optional     pam_reauthorize.so prepare
auth required pam_google_authenticator.so nullok
- Now edit ssh file to enable two-factor authentication when ssh into the machine
 
sudo nano /etc/ssh/sshd_config
- Find “ChallengeResponseAuthentication” in the file and set it to “yes”
 
. . .
# Change to no to disable s/key passwords
ChallengeResponseAuthentication yes
#ChallengeResponseAuthentication no
. . .
- Restart the ssh service
 
sudo systemctl restart sshd.service
- You are now done with setting up two-factor authentication
 
https://www.techrepublic.com/article/how-to-set-up-two-factor-authentication-on-centos-7/
For help: [email protected]