Skip Password Prompts for Sudo commands

When administrating a development machine or server you may find yourself needlessly entering sudo password. On a production machine this is something you’d want but for a local or develpment machine not so much.

Here’s how you can bypass the password:

Open the /etc/sudoers file (as root, of course!) by running:

sudo visudo

Note you should never edit /etc/sudoers with a regular text editor, such as Vim or nano, because they do not validate the syntax like the visudo editor.

At the end of the /etc/sudoers file add this line replacing username with your actual username:

username     ALL=(ALL) NOPASSWD:ALL

Save the file and exit with <ESC>wq. If you have any sort of syntax problem, visudo will warn you and you can abort the change or open the file for editing again.It is important to add this line at the end of the file, so that the other permissions do not override this directive, since they are processed in order.

Note that for mac the save steps are a little different because mac uses vim for visudo edits.  Press the Escape key. Then, type :wq and press enter. This saves the file and quits vim.

Finally, open a new terminal window and run a command that requires root privileges, such as sudo apt-get update. You should not be prompted for your password!