visudo and add the following line:
%user_name ALL=(ALL) NOPASSWD: /sbin/poweroff, /sbin/reboot, /sbin/shutdown
This allows you to run the above three commands, using sudo, however with no password.
sudo poweroff will now result in a passwordless shutdown.
However, to make this even cleaner, we'll add an alias, so that running
sudo shutdown now.
~/.bash_aliases for editing.
Insert the following line at the end of the file:
alias shutdown='sudo shutdown now'
Finally, load the changes to the
Try it out!