Securing sudo and su with Google authenticator

What you need

git autoconf automake make libtool pam-devel
git clone http://github.com/google/google-authenticator-libpam.git
cd google-authenticator-libpam/
# In the directory run
./bootstrap.sh
./configure
make
sudo make install
# Copy the files and change suffix to .bak (for backup)
cp /etc/pam.d/su ~/su.bak
cp /etc/pam.d/sudo ~/sudo.bak
vi /etc/pam.d/sudo
#%PAM-1.0
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
#%PAM-1.0
auth sufficient pam_rootok.so
auth sufficient /usr/local/lib/security/pam_google_authenticator.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficient pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
#auth required pam_wheel.so use_uid
auth substack system-auth
auth include postlogin
account sufficient pam_succeed_if.so uid = 0 use_uid quiet
account include system-auth
password include system-auth
session include system-auth
session include postlogin
session optional pam_xauth.so
vi /etc/sudoers.d/local
Defaults timestamp_timeout=30
$ google-authenticator
Do you want authentication tokens to be time-based (y/n) y
Do you want me to update your "/home/<USER>/.google_authenticator" file? (y/n) yDo 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) y
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

Conclusion

--

--

--

Munich Metal | Cardano Ambassador | I want to show how tech can help you | 🇩🇪 & 🇬🇧

Love podcasts or audiobooks? Learn on the go with our new app.

Meet our new CSO: Jason Butler.

Our Community Edition 2.0 Brings Turbocharged Security Testing Capacities

3 things each online business ought to be mindful about

Best cybersecurity software solutions for small business — 5 cyber security software tools

Zoin.Consistent update 3.

From the Basement to the Boardroom — AppSec Business Impact is on the Rise

Blocking Tor: A Case for Better Detection

TryHackMe - Kenobi Walkthrough

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alex | @ruttkowa

Alex | @ruttkowa

Munich Metal | Cardano Ambassador | I want to show how tech can help you | 🇩🇪 & 🇬🇧

More from Medium

Best Proxy Scrapers for 2022

Setting a Dynamic Date filter in QuickSight (AWS)

Taking a closer look at the Network Stack

Verifying hash with PowerShell (for terminal lovers)