35

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.

2
  • 2
  • 2
    because if an attacker has physical access to your computer, you've lost already. Attempting to prevent someone who is within arms reach of the box from doing almost anything is at best a delaying tactic and mostly causes more inconvinience for day-to-day users than it would for an attacker. Most Linux distros will give you a root prompt if spoken to sternly during bootup for exactly this reason. Jan 8, 2016 at 12:03

2 Answers 2

33

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

7
  • is it secure?? 'you could have it do whatever you want.'
    – amyassin
    Aug 10, 2011 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. Aug 10, 2011 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) Aug 10, 2011 at 18:00
  • 9
    @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, 2011 at 20:23
  • 3
    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, 2011 at 7:11
11

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .