Here's one way.
1) Created a new group named "pwroff"
Code:
root@corvette:~# groupadd pwroff
2) Then find what groups you belong too & add yourself to the group:
Code:
root@corvette:~# groups hammer
hammer : users
root@corvette:~# usermod users,pwroff hammer
3) Then edit /etc/sudoers, using visudo, to add the commands for the pwroff group.
Code:
root@corvette:~# visudo
Then add these 2 lines at the bottom:
NOTE: If you don't want to have to enter root's password to shutdown then set the NOPASSWD flag.
Code:
%pwroff corvette = NOPASSWD: /sbin/poweroff
%pwroff corvette = NOPASSWD: /sbin/reboot
4) Then add a couple 1 line scripts to your $PATH so you can just invoke the command "poweroff" & "reboot", without having to enter the whole thing. I choose /usr/bin for these scripts because it comes after /sbin in root's $PATH, meaning the actual reboot & poweroff commands would still be invoked by root instead of these 2 scripts. Anyway, make sure you don't overwrite the real poweroff & reboot programs, wherever they are.
Code:
cat > /usr/bin/reboot << "EOF"
#!/bin/sh
sudo /sbin/reboot
EOF
Code:
cat > /usr/bin/poweroff << "EOF"
#!/bin/sh
sudo /sbin/poweroff
EOF
5) Now change the group and permissions on these 2 scripts:
Code:
chgrp pwroff /usr/bin/poweroff
chgrp pwroff /usr/bin/reboot
chmod ug+x /usr/bin/poweroff
chmod ug+x /usr/bin/reboot
That's it, now anyone that is a member of the pwroff group can reboot & poweroff the PC without a password or without being root.