Securing sudo and su with Google authenticator

What you need

git autoconf automake make libtool pam-devel
git clone
cd google-authenticator-libpam/
# In the directory run
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
auth sufficient /usr/local/lib/security/
auth include system-auth
account include system-auth
password include system-auth
session optional revoke
session required
vi /etc/pam.d/su
auth sufficient
auth sufficient /usr/local/lib/security/
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficient trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
#auth required use_uid
auth substack system-auth
auth include postlogin
account sufficient uid = 0 use_uid quiet
account include system-auth
password include system-auth
session include system-auth
session include postlogin
session optional
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





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)