Sudo command without giving password

In this article let’s discuss about Sudo command without giving password. Let’s go through the following methods without any delay.

Method 1:

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

If you are facing any issues with the above approach then try the alternative that is given below. It may look similar but have a try!

Method 2 :

# Run `visudo` to edit the file `/etc/sudoers`:
sudo visudo

# For example, to allow the `shutdown` command to run without a password. 
# Add this to the file, replacing `myusername` with your own login name for your PC:
myusername ALL = NOPASSWD: /sbin/shutdown

# NOTE: `sudo` is still required to run the command so you still have to specify the command as:
sudo shutdown

Hope the above solution works.

Realted Posts : How to undo last commit but keep changes