r/bashtricks • u/BooeySays • Apr 25 '20
[Tip] How to remove root password prompt for specific apps
if you find yourself running certain root commands alot and you're tired of typing in that long ass password of yours, here is how you can turn off the root password prompt for some of those commands.
You will need:
root access
log in name
whereis installed
So for this example, I will be turning the password prompt OFF for the apt-get command, and the visudo command.
So you can see that I am asked to enter my password in order to update apt-get:

To disable the prompt for that command, we first need to find out where that command is, so run:
whereis apt-get
You will usually see a few different locations. The only one that concerns us is the first location. In this case, it is /usr/bin/apt-get
Do the same thing for visudo and we get the location /usr/sbin/visudo

Remember those locations.
Next step, run visudo by running:
sudo visudothen scroll the cursor down to the line that says: "%sudo ALL=(ALL:ALL) ALL"

Hit CTRL+K to cut the whole line, then hit CTRL+U to paste it back.
Hit enter to got to the next line, then hit CTRL+U to paste it on that new line. This is the line we will be editing.

We will want to edit %sudo, and change it to our LOGIN name. It is the name usually found at the beginning of the terminal prompt. In my case it is "booey", so I will change %sudo to %booey.

if you dont know your LOGIN name, you can find it by running:
echo $LOGNAME
Next, change the last "ALL" in the line to "NOPASSWD:", then enter locations of the commands we found at the start, seperating the two locations with a comma and a space

Hit CTRL+X, hit "Y" to say yes to save, and then ENTER to confirm
Thats it, you're done.
Now when you try to run those commands with sudo, you won't get asked the password!

How that was useful.. Cheers!