Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 interface?? and why it doesn't need the password or the root privileges?? thank you...

I'm using Ubuntu 11.04 Natty...

share|improve this question
add comment

2 Answers

up vote 21 down vote accepted

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

share|improve this answer
    
is it secure?? 'you could have it do whatever you want.' –  amyassin Aug 10 '11 at 17:52
7  
To get acpid to do something different than it already does, you'd have to be root, so you'd already have permission to do insecure things. It is also possible to use MAC systems like SELinux to protect acpid, restricting the things they are allowed to do, even while they run as root. –  Warren Young Aug 10 '11 at 18:00
5  
@amyassin Well, to change what it does you need root privileges; a normal user can't tell it what to do. But acpid is configurable, it can run different scripts depending on the hardware events it sees (for example, I have acpid lock my computer when I hit the power button) –  Michael Mrozek Aug 10 '11 at 18:00
2  
@amyassen If someone has physical access to your machine then it's too late to worry about security -- if the power button doesn't trigger a graceful shutdown they can just pull the power cord and cause an ungraceful shutdown. –  Shadur Aug 10 '11 at 20:23
2  
Said 'malicious software' would have to get root ownership and SUID permissions in order to tell init to make with the shutdown -- and again, by the time it gets to that point you have bigger problems to worry about than a possible shutdown. –  Shadur Aug 11 '11 at 7:11
show 3 more comments

Michael's answer correctly discusses system function when using the hardware power switch, but most desktop environments actually use dbus for this purpose rather than doing it themselves. For example, GNOME uses dbus's org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown when the shutdown button is clicked. When this is sent, dbus does some checks to determine whether the user sending the message is authorised to perform a shutdown, and if they are, it shuts down the system.

You can emulate this by using dbus-send. For example, to shut down your system using dbus, use something like this:

dbus-send --system --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.