Saturday, April 27, 2024
 Popular · Latest · Hot · Upcoming
50
rated 0 times [  50] [ 0]  / answers: 1 / hits: 36125  / 2 Years ago, fri, september 30, 2022, 7:10:34

When we install/remove/update packages or make any changes which require administrative privileges we are prompted for the password of admin user who has the sudo privileges - this happens both via GUI and terminal.



prompt via gui



However, if we try to shutdown and restart via terminal, it complains that we need to be root:



$ reboot
reboot: Need to be root

$ shutdown now
shutdown: Need to be root


But we are never asked for a password when we perform these actions via the cog-wheel at top right.



cog-wheel menu



Why is there this discrepancy?


More From » sudo

 Answers
4

The shutdown on the cog-wheel checks if you are allowed to shutdown the machine. This is done via PolicyKit. In case of shutdown this statement in the file /usr/share/polkit-1/actions/org.freedesktop.consolekit.policy is checked:



<action id="org.freedesktop.consolekit.system.stop">
<description>Stop the system</description>
<message>System policy prevents stopping the system</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
</action>


The PolicyKit triggers a dbus-send command. In case of shutdown it would be:



dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown


There is a daemon running in the background with root-Privileges that invokes the shutdown command for you.



When you want to be able to shutdown the machine "the old way" via command line (shutdown, reboot, halt, ...), then you need to add the suid-Bit to those commands. But be aware, everyone on your system, that has access to the shell could then shutdown your machine.


[#28902] Saturday, October 1, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
pilun

Total Points: 270
Total Questions: 100
Total Answers: 94

Location: England
Member since Sat, Feb 13, 2021
3 Years ago
;