How do you harden sudo in production?
IntermediateProductionSSH & Access Hardening
Answer
- Use groups and files in
/etc/sudoers.d/, managed by config management and validated withvisudo -cf. - Avoid blanket
NOPASSWD: ALLfor humans; scope service accounts to exact commands. Defaults use_ptyandDefaults logfile=/var/log/sudo.log, or I/O logging (log_output) for sensitive hosts.Defaults timestamp_timeout=5.- Ship sudo logs centrally.
- Never allow commands that spawn shells (
vi,less,find,awk,python); usesudoeditfor file edits.
More on SSH & Access Hardening
What are the first sshd_config changes you make on a new production server?BeginnerWhy use a drop-in file in /etc/ssh/sshd_config.d/ instead of editing sshd_config?IntermediateWhy disable SSH password authentication entirely?BeginnerShould you change the SSH port from 22?IntermediateWhat are SSH certificates and why do large fleets use them?AdvancedHow do you restrict what a specific SSH key can do?Advanced