Are you tired of typing your sudo password any time that you need to execute a command with root privileges? We’ve got good news: it’s possible to disable the sudo password, which will bypass the password prompt whenever you type a command with sudo.
These instructions will work the same whether you’re using Ubuntu, Debian, Arch Linux, Manjaro, Fedora, or any other system that has sudo access configured.
Permanently Disable Sudo Password Prompt
To avoid the sudo prompt ever showing up when you execute a sudo command, follow the instructions below.
1. Type the following command to edit the
$ sudo visudo
2. At the bottom of this file, append the following line, while replacing
linuxnightly with the name of your user account.
linuxnightly ALL=(ALL) NOPASSWD: ALL
Save your changes and exit the file when done, and the changes will take effect immediately.
3. If you would like to grant every user the ability to bypass the sudo password prompt, you’ll want to append this code instead.
%sudo ALL=(ALL:ALL) NOPASSWD: ALL
All done. If you need to revert these changes, simply delete the line that you appended to the file.
Supply Sudo Password in Command
If you don’t want to permanently disable the sudo password, you could alternatively supply the sudo password in a command. This relies on sudo’s
-S option, which will accept input from stdin.
You should also use the
-k option, which will ensure that you get prompted for a password, even if you recently supplied it and have cached credentials.
1. As an example, we’ll run the
whoami command with sudo privileges. Notice we supply our password with the
echo command first.
$ echo 'password' | sudo -S -k whoami root
2. Note that the command above will show up in your terminal history, and also will be viewable by anyone looking over your shoulder. A better method is to put your sudo password in a secure file.
$ echo 'password' > ~/.sudopass.txt $ chmod 400 ~/.sudopass.txt
3. Now you can reference this file to supply a password in your sudo command.
$ cat ~/.sudopass.txt | sudo -S -k whoami