Tools
Log in
English

Learn to codeSecurity check

sudo without a password

MediumL12Linux servers

Find NOPASSWD rules and either limit them to the commands you really need or…

What is the risk

If an account with NOPASSWD is compromised, the attacker becomes root without any password.

Default cloud accounts (ubuntu, ec2-user and so on) often have it.

How to check

Linux

sudo grep -rn NOPASSWD /etc/sudoers /etc/sudoers.d/
sudo -l -U ubuntu

Replace ubuntu with the account to check.

How to fix

Linux

sudo passwd ubuntu
sudo visudo -f /etc/sudoers.d/90-cloud-init-users

Set a password for the account first, then remove NOPASSWD: from the file. For jobs that really need it, allow one command only, like deploy ALL=(root) NOPASSWD: /usr/bin/systemctl reload nginx. Use the file name you found.

How to prevent it

  • Always edit sudoers with visudo. A syntax error can lock sudo completely.
  • Check the sudo log now and then (/var/log/auth.log or journalctl _COMM=sudo).
  • Keep sudo itself up to date.

Check again after fixing

Linux

sudo grep -rn NOPASSWD /etc/sudoers /etc/sudoers.d/

Any remaining line should name a single command.

Run the downloaded check again and make sure this item passes.

Related CVEs

HighCVE-2021-31567.8

Security check home