How to execute sudo without password prompt

How to execute sudo without password prompt
Photo by Markus Spiske / Unsplash
💡
Never, I repeat NEVER, disable password prompt on your production systems, as this is a serious security risk and could harm your system!

When working in development environments it is pretty annoying that sudo tasks require you to enter your password. But this behaviour can be disabled very easily with editing the file /etc/sudoers.

💡
Never, I repeat NEVER, edit the sudoers file directly using vim or something different as you could potentially destroy your system.

We open the sudoers-file using the visudo command: sudo visudo.

This opens a nano editor, which checks the file contents on syntactical correctness when you try to save it and therefore preventing you from corrupting your system.

After opening the file with visudo you simply add the following line at the end of the file:

$USER ALL=(ALL) NOPASSWD: ALL

Please replace $USER with your own username, that should be able to execute sudo without a password prompt.

Finally you have to save your additions and close the sudoers file. For this press CTRL + X and Y. Hit Enter to leave nano.

💡
If you've made an error a warning will appear:
>>> /etc/sudoers: syntax error <<<
Simply type e to edit the sudoers-file again or x to quit without saving your changes. 

After this you should be able to execute sudo commands with being asked for your password.