Wednesday, May 18, 2016

Command to make sudo not to ask for password (bash one-liner)

By default Ubuntu users forced to type password every time when they perform root operations.
You can use this snippet to avoid it:

sed -i "/^%admin/ {/NOPASSWD/! s/ALL$/NOPASSWD:ALL/}" /etc/sudoers
sed -i "/^%sudo/ {/NOPASSWD/! s/ALL$/NOPASSWD:ALL/}" /etc/sudoers


Here is how to read it:
* find only strings that start with %admin
* skip them if they already contain NOPASSWD
(so you can safely run this script many times)
* substitute last(on the line) matching of word "ALL" with NOPASSWD:ALL


No comments:

Post a Comment