How to Disable Password Prompts in Ubuntu Easily

Updated

Linux ls command listing files in a terminal

To skip the sudo password prompt for one specific command on Ubuntu, give that command its own NOPASSWD rule in a drop-in file under /etc/sudoers.d/ — never a blanket NOPASSWD: ALL. Create the drop-in with visudo, name the exact binary by absolute path with its arguments, then confirm the whole ruleset still parses:

sudo visudo -f /etc/sudoers.d/90-nopasswd-deploy

# put exactly this in the file, one line:
yourname ALL=(root) NOPASSWD: /usr/bin/systemctl restart nginx

# then confirm the whole ruleset still parses:
sudo visudo -c

That one line removes the prompt for the one command you actually run repeatedly. Nothing else changes.

Do not change %admin ALL=(ALL) ALL to %admin ALL=(ALL) NOPASSWD: ALL. That gives every member of an administrator group the ability to become root, from any process, with no authentication — including any program that is already running as you.

Why blanket NOPASSWD is a different thing from what you think you are turning off

The password prompt is not a dialog you dismiss — it is the only thing standing between a process running as your user and full root. Once NOPASSWD: ALL is in place, anything running under your account can run sudo silently: a malicious npm postinstall script, a compromised browser extension with shell access, a shell history replay, an attacker who got your unlocked laptop for thirty seconds. There is no second check.

Use /etc/sudoers.d/, not /etc/sudoers

Use a drop-in rather than the main file: it survives package upgrades cleanly, it is one rm to undo, and a mistake is contained. The mechanism is an include directive in the main sudoers file, and it does exactly what you would hope — visudo -c validates the drop-ins too. Tested here against sudo 1.9.17p2, with a main file containing @includedir …/sudoers.d:

$ visudo -c -f main.sudoers
main.sudoers: parsed OK
.../sudoers.d/90-deploy: parsed OK

There is a naming rule that trips people, and it is worth knowing in both directions. Files in sudoers.d whose names contain a . or end in ~ are ignored. Demonstrated by putting deliberately invalid content into one file and renaming it three times:

Filename Content visudo -c result
90-deploy.bak garbage exit 0 — skipped, never read
91-broken same garbage exit 1 — read and rejected
90-deploy~ same garbage exit 0 — skipped, never read

So a rule saved as deploy.conf silently does nothing and you will hunt for why — but the same rule stops your editor’s 90-deploy~ backup taking effect on its own.

The lockout risk, and the exit code that prevents it

A sudoers file that does not parse is not partially applied — sudo refuses to run. If that happens on a machine with no root password and no console access, you are locked out of administration entirely. This is why the rule is always “edit through visudo, never through a plain editor”: visudo validates before it installs.

You can check any candidate file without touching the live one. visudo -c -f FILE is check-only and returns a usable exit code. Run against several candidates on sudo 1.9.17p2:

$ visudo -c -f f.sudoers        # deploy ALL=(root) NOPASSWD: /usr/bin/systemctl restart nginx
f.sudoers: parsed OK
exit=0

$ visudo -c -f f.sudoers        # %sudo ALL=(ALL) NOPASSWD ALL      <- missing colon
f.sudoers:1:26: syntax error
%sudo ALL=(ALL) NOPASSWD ALL
                         ^~~
exit=1

$ visudo -c -f f.sudoers        # %sudo ALL (ALL) NOPASSWD: ALL     <- missing '='
f.sudoers:1:11: syntax error
%sudo ALL (ALL) NOPASSWD: ALL
          ^
exit=1

$ visudo -c -f f.sudoers        # Defaults nopasswd_all             <- invented option
f.sudoers:1:22: unknown defaults entry "nopasswd_all"
exit=1

Two habits follow: validate before you install, and keep a second terminal with an authenticated sudo session open while you edit, so you can revert if the new rules lock you out.

The four candidate files above, and the .bak and ~ naming cases from the previous section, are replayed by a script that runs visudo -c -f only on files in its own temporary directory; it never reads or changes the real /etc/sudoers or /etc/sudoers.d.

The administrator group on current Ubuntu is sudo, not admin

On current Ubuntu the administrator group is sudo. cloud-init's Ubuntu defaults set the first user's groups to adm, cdrom, dip, lxd, sudo — no admin group at all. The %admin line was an Ubuntu-specific addition layered on top of Debian's %sudo line, and it is long gone from new installs. Check yours rather than guessing:

id -nG                 # your groups
sudo -l                # what sudo will actually let you do, rules resolved

sudo -l is the one to trust. It prints the effective ruleset after all includes, aliases and overrides, which is not always what reading the files suggests.

"Save file by hitting Ctrl-X" is editor-specific

Ctrl-X is nano's exit key. visudo opens whatever editor your system is configured to use, which is nano on some systems and vi on others — and in vi, Ctrl-X does nothing useful; the sequence is :wq. Rather than guess, name the editor:

sudo EDITOR=nano visudo -f /etc/sudoers.d/90-nopasswd-deploy

Scope it properly if you do use it

Two things about the scoped form are worth stating, because "specific command" is easy to get wrong:

# fine - one binary, fixed arguments
yourname ALL=(root) NOPASSWD: /usr/bin/systemctl restart nginx

# NOT scoped - parses fine, grants far more than it looks like
yourname ALL=(root) NOPASSWD: /usr/bin/systemctl *

Both of those pass visudo -c cleanly — verified above. The wildcard version permits systemctl with any arguments, and there are arguments to systemctl that get you a root shell. A rule that parses is not a rule that is safe. Always use an absolute path, and prefer naming the arguments over a wildcard.

If a service account genuinely needs unattended privileged commands, that is what the scoped drop-in is for. A human account with NOPASSWD: ALL is not a convenience decision, it is a security decision, and it should be made deliberately rather than because a prompt was annoying.

Give that service account no usable password at all rather than a scripted one: an SSH key plus passwd -l leaves nothing to guess, and if a password really has to be set from a script, it goes in on standard input — anything passed as a command argument is readable from /proc by every other user on the box.

How to undo it

sudo rm /etc/sudoers.d/90-nopasswd-deploy
sudo visudo -c

What was actually run for this article

The real /etc/sudoers on the test machine was never opened, read, or modified. Every syntax result above came from visudo -c -f pointed at throwaway files in a temporary directory, and every drop-in test used a temporary @includedir directory, not the system one.

Those checks ran on macOS 26.6, which ships sudo 1.9.17p2 — the same upstream release Ubuntu 26.04 publishes (as sudo 1.9.17p2-1ubuntu3, per the Launchpad API), so it is the same parser and the same sudoers grammar. That is why the syntax and drop-in behaviour transfers; it is not a claim that anything was run on Ubuntu, because no Ubuntu machine was used. The Ubuntu group-name facts come from cloud-init's upstream configuration template and from the Ubuntu sudo source package, both downloaded and read.

Photo of author
Sudhir P. founded HeatWare.com in 1999 and has built and operated it full-stack ever since; it is now used by more than 88,000 people. He writes here about the PostgreSQL, MySQL, Linux and DevOps work that keeps it running. Articles are rewritten only after the commands in them have actually been run, and the verification scripts are published alongside them so anyone can check the claims. Reach him at blog@heatware.net.