Open up a terminal (CTRL + T)
and type the following sudo visudo
Add the following line:
%group_name ALL=(ALL) NOPASSWD: /sbin/poweroff, /sbin/reboot, /sbin/shutdown
or
user_name ALL=(ALL) NOPASSWD: /sbin/poweroff, /sbin/reboot, /sbin/shutdown
This allows the user/group to run the above three commands, using sudo, however with no password.
So, sudo poweroff
will now result in a passwordless shutdown.
However, to make this even cleaner, we'll add an alias, so that running shutdown
calls sudo shutdown now
.
Open ~/.bash_aliases
for editing.
nano ~/.bash_aliases
Insert the following line at the end of the file:
alias shutdown='sudo shutdown now'
Finally, load the changes to the .bash_aliases
file...
source ~/.bash_aliases
Try it out!
shutdown
Thanks, Eric.
poweroff
andshutdown now
works from terminal. In Ubuntu 20,04, but I an sure that it has been like that for years.