# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum install google-authenticator
# google-authenticator
Do you want authentication tokens to be time-based (y/n) y
Do you want me to update your "/home/sammy/.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
* SSH
# vi /etc/pam.d/sshd
auth required pam_google_authenticator.so nullok
#auth substack password-auth
...
# /etc/ssh/sshd_config
ChallengeResponseAuthentication yes
AuthenticationMethods publickey,password publickey,keyboard-interactive
...
# cd ~/.ssh
#mv authorized_keys authorized_keys.bak
# systemctl restart sshd.service
* sudo / su
# yum install -y git autoconf automake make libtool pam-devel
# git clone https://github.com/google/google-authenticator-libpam.git
# cd google-authenticator-libpam/
# ./bootstrap.sh
# ./configure
# make
# make install
# vi /etc/pam.d/sudo
auth sufficient /usr/local/lib/security/pam_google_authenticator.so
auth include system-auth
account include system-auth
password include system-auth
session optional pam_keyinit.so revoke
session required pam_limits.so
...
# vi /etc/pam.d/su
auth sufficient /usr/local/lib/security/pam_google_authenticator.so
auth required /usr/local/lib/security/pam_google_authenticator.so
---
$ sudo su
Verification code: