Home Linux guides How to Disable the “Sudo” Password in Ubuntu 20.04

How to Disable the “Sudo” Password in Ubuntu 20.04

51
0

When a user is added to the system with superuser privileges, he is able to execute commands as the root user. He does this by issuing the sudo command. sudo is the short form for ‘superuser do’. This command temporarily elevates a normal user to a superuser or root user. Whenever this user issues a sudo command, he is prompted for a sudo password before the execution of the command.

In this brief guide, we will look at how to disable the sudo password in Ubuntu 20.04. In the previous article How to Add User to Sudoers & Add User to Sudo Group in Rocky Linux 8, we created a user and added them to the wheel group / sudo group. You can check the guide for a brief recap.

Disabling the sudo password in Ubuntu 20.04

To disable the sudo password in Ubuntu 20.04, carry out the few steps below.

Step 1 : Access the Sudoers File

Sudoers file is the default sudo security policy plugin that determines a user’s sudo privileges. This policy is driven by the /etc/sudoers
file.

To view the contents of the /etc/sudoers file, run the command:

sudo visudo

Enter your sudo password and press Enter to access the file.

Step 2 : Scroll to #includedir /etc/sudoers.d

Scroll down through your file to the /etc/sudoers.d file.

below this file, define the user with sudo privileges who wish to disable the sudo password.

As shown below.

#includedir /etc/sudoers.d
jil ALL=(ALL) NOPASSWD:ALL   ##define your sudo user here ## 

See screenshot :

Disable-sudo-password

In the screenshot, user jil has been added to the default sudo security policy plugin and NOPASSWD issued to disable the password.

Save and exit your text editor.

Step 3 : Test by executing a command on the terminal

After you have saved your settings and exited your editor, on your terminal run any command. You will not be prompted to enter the password.

If in the future you decided to remove this behavior, go back to the file and either delete the user or comment him out.

#includedir /etc/sudoers.d
#jil ALL=(ALL) NOPASSWD:ALL  

Golden Tip

To make the currently logged in user a sudoer and make sudo not prompt them for the password, run the command :

echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/$USER

This command will create a new file /etc/sudoers.d/$USER where $USER is the username of the user that you were logged in as when you ran that command.

To do this for a different user, replace both instances of $USER with the username of the different user.

echo "otheruser ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/otheruser

A single file can be used to manage many directives:

echo "username ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee -a /etc/sudoers.d/local

Conclusion

This practice is not recommended and should be used with lots of caution. It is a huge security breach. If your system fell into the wrong hands, you could have all your files deleted in a twinkling of an eye. Always be very cautious.

That sums up our article, we hope it has been helpful.

See more resources below:

LEAVE A REPLY

Please enter your comment!
Please enter your name here