Checks / Users

sudo without a password is allowed

Check
users.sudo_nopasswd
Severity
low
Runs
on the server, in the daily run of the collector
Looks at
NOPASSWD in /etc/sudoers or /etc/sudoers.d
Updated 26 Nov 2026

What the check looks at

The tag NOPASSWD in /etc/sudoers and in the files of /etc/sudoers.d/ that sudo reads (it skips names with a dot or a trailing ~). The check warns and reports, for each rule, the user or group, the number of commands, and the file and line, for example deploy: NOPASSWD for 1 command (/etc/sudoers.d/deploy:1).

Risk

Anyone who gets a shell as that user (a stolen SSH key, an exploited web application running as that user, a malicious package in their home directory) becomes root at once; with a password prompt, they also need the password. Many cloud images set this up on purpose: cloud-init gives the default user (ubuntu, debian, rocky and so on) ALL=(ALL) NOPASSWD:ALL in /etc/sudoers.d/90-cloud-init-users. For that reason the severity is low and the check only warns.

How to fix it

Find the rules:

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

For a person, give the account a password and remove NOPASSWD:

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

Change ALL=(ALL) NOPASSWD:ALL to ALL=(ALL) ALL, or delete the file if the user is in the sudo group (Debian, Ubuntu) or the wheel group (RHEL, Rocky, Alma), which grants sudo with a password. Test in a second session with sudo -k; sudo -v before you close the first one.

cloud-init runs its user module once per instance, so the change stays across reboots. For new servers, set sudo: ["ALL=(ALL) ALL"] for the default user in your cloud-init user data.

For automation, allow only the command it needs, with its arguments:

deploy ALL=(root) NOPASSWD: /usr/bin/systemctl restart myapp.service

On Alpine, sudo comes from the community repository; with doas, the nopass keyword in /etc/doas.conf does what NOPASSWD does.

How to check the fix

sudo visudo -c
sudo -l -U ubuntu

visudo -c must report parsed OK for every file. sudo -l -U lists the rules of the user; NOPASSWD should appear only on narrow command rules.

When a warning is fine

For accounts that only automation uses (CI deployments, configuration management), with rules limited to the commands they run. For a person, accept the result only when the account does not have a password and logs in with a key protected by a passphrase or a hardware token. Even then, a stolen session becomes root.

An accepted result stays out of the digest and the counts until it changes.

Sources