root gui shutdown – How the Power Button Shuts Down the Computer Without Root Permission

guirootshutdown

When I try to shutdown the computer from a command line or terminal I must have root privileges:

amy@amy:~$ shutdown now
shutdown: Need to be root

and

amy@amy:~$ halt
halt: Need to be root

but when shutting down using the graphical user interface, i.e. shutdown button, or the hardware shutdown button, I'm not asked for the password to do so. What does that shutdown for the graphical interface, and why it doesn't need the password or root privileges?

I'm using Ubuntu 11.04 Natty.

Best Answer

The hardware power button triggers an ACPI event that acpid (the ACPI daemon) notices and reacts to; in this case by shutting down the system, although you could have it do whatever you want. The ACPI daemon runs as root, so it has permission to shutdown the system. Desktop environments (e.g. gdm for Gnome) typically run as root as well, so I suspect they work the same way -- you don't have permission to shutdown the system, but you can tell gdm you want it shut down and it can do it on your behalf

Related Question