If it fails, you need to edit /etc/sudoers file and add :
Code:
<your username> <your hostname> = NOPASSWD: /sbin/shutdown -h now, /sbin/poweroff, /sbin/reboot
And to shut down your machine :
sudo /sbin/shutdown -h now
or:
sudo /sbin/poweroff
to reboot:
sudo /sbin/reboot
Note that the command have to be typed exactly as above, eg
sudo poweroff <-- will not work