Checks / Users

sudo without a password is allowed

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

What the check looks at

The agent looks for the tag NOPASSWD in /etc/sudoers and the files in /etc/sudoers.d/, and reports the file and the user or group the rule applies to.

Why it matters

With NOPASSWD, the user runs commands as root without typing a password. Then anyone who gets a shell as that user (a stolen SSH key, an exploited web application running as that user, a malicious package installed in their home directory) becomes root at once. With a password prompt, they also need the password.

Many cloud images create this situation 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. That is why 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 wheel group (RHEL, Rocky, Alma), which already 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. To keep new servers from getting the rule, 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

The same lines work on all distributions. On Alpine, sudo comes from the community repository; with doas, the equivalent of NOPASSWD is the nopass keyword in /etc/doas.conf.

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 used only by automation (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 that is protected by a passphrase or a hardware token; even then a stolen session becomes root.

An accepted result is left out of the digest and the counts until it changes; then it shows again.

Sources