Run Sudo Without a Password on Ubuntu 24.04

One of the first challenges after logging into a freshly installed Ubuntu system is the frequent need to enter your password for administrative tasks, such as:

$ sudo apt update
[sudo] password for rostyslav:

If you need to run many commands requiring administrative privileges, especially with frequent system reboots, this can quickly become a repetitive and time-consuming task.

To streamline this process, you can configure sudo to allow running privileged tasks without requiring a password every time.

Verify your user belongs to the sudo group

Run the following command to check if your user is a member of the sudo group:

$ groups
rostyslav adm cdrom sudo dip plugdev lxd

Edit the sudo configuration

To enable passwordless sudo, use the visudo command. This ensures safe editing of the configuration file:

$ sudo visudo
[sudo] password for rostyslav:

By default, this opens the nano editor with the /etc/sudoers.tmp file.

Modify the sudo group settings

Scroll down to find the following line:

%sudo   ALL=(ALL:ALL) ALL

To allow passwordless sudo, modify it by adding "NOPASSWD:" before the last "ALL":

%sudo ALL=(ALL:ALL) NOPASSWD:ALL

Save the changes and exit the nano editor by pressing Ctrl+X, typing Y to confirm, and pressing Enter to save the file.

Verifying the sudo Group Settings

To ensure the recently modified configuration is correct, use the visudo command with the -c option:

$ sudo visudo -c
/etc/sudoers: parsed OK
/etc/sudoers.d/README: parsed OK

The parsed OK status indicates that the /etc/sudoers file is properly configured.

Now, members of the sudo group can execute commands with sudo without being prompted for a password.