In this tutorial we learn how to enable passwordless sudo in Ubuntu. I use Ubuntu 20.04 for this tutorial, but you should be able to follow this tutorial on older versions of Ubuntu like Ubuntu 18.04 or newer version like Ubuntu 20.04 or Ubuntu 21.04.
sudo configuration in Ubuntu is located in
/etc/sudoers. This file contains the following line
which will include any file in the
/etc/sudoers.d directory that do not end with
~ or contain
To enable passwordless sudo for spesific user, we can create new file in
/etc/sudoers.d/ directory. I recommend creating one file for each user for easy to manage access.
In the following example I will allow passwordless sudo for username
Edit the new file using
visudo command. While this is not mandatory but visudo can help you ensure that the sudo configuration that you’re editing is correct.
Error in sudoers files can lead to losing access to the system.
We can use the following command to edit the new file
sudo visudo /etc/sudoers.d/howtodojo
Enter the following configuration. Replace the
<username> below with your username.
username ALL=(ALL) NOPASSWD: ALL
If you use default editor, nano, you can press
CTRL+X, then choose
Y. Now your username already have passwordless sudo on the system.
You can change visudo default editor if you prefer another editor when editing