PortGate

Blueprints · Server Hardening

Beginner 10 min · Linux

sudo command logging

Stages a sudoers drop-in that logs every sudo command. It does not grant NOPASSWD.

Baked-in protections

Step 1 · conf

sudoers drop-in

/root/portgate-blueprints/portgate-sudo-log

Install with visudo -f. A syntax error in sudoers can lock out root sudo.

Defaults logfile="/var/log/sudo.log"
Defaults log_input,log_output

Step 2 · bash

Read-only check

/root/portgate-blueprints/sudo-check.sh

Prints status. It does not change the service.

#!/bin/sh
set -eu
sudo -n -l >/dev/null 2>&1 && echo "This user can run sudo without a password." || echo "sudo still asks for a password, or this user is not a sudoer."