I am reading the book Linux kernel development, in chapter 5 "System Call Implementation" page 77 says

For example, capable(CAP_SYS_NICE) checks whether the caller has the ability to modify nice values of other processes. By default, the superuser possesses all capabilities and nonroot possesses none. For example, here is the reboot() system call. Note how its first step is ensuring that the calling process has the CAP_SYS_REBOOT . If that one conditional statement were removed, any process could reboot the system.

However, in my Debian Sid I can reboot my machine by using gnome or by executing /sbin/reboot without sudo or su. How is this possible?

Maybe with systemctl?

ls -l /sbin/reboot 
lrwxrwxrwx 1 root root 14 Jun 28 04:23 /sbin/reboot -> /bin/systemctl

EDIT: My user groups

[damian@xvz:~]$ groups 
damian sudo wireshark bumblebee

EDIT 2: systemctl permissions

[damian@xvz:~]$ ls -l /bin/systemctl 
-rwxr-xr-x 1 root root 626640 Jun 28 04:23 /bin/systemctl
  • Maybe is systemctl.  What does ls -l /bin/systemctl tell you? – G-Man Jul 17 '15 at 20:03
up vote 10 down vote accepted

This is done via an authorization manager called polkit:

polkit provides an authorization API intended to be used by privileged programs (“MECHANISMS”) offering service to unprivileged programs (“SUBJECTS”) often through some form of inter-process communication mechanism.

With systemd and polkit users with non-remote session can issue power related commands. You can list all polkit registered actions and get details about any of them with pkaction (invoked with no arguments it will list all action ids).
In this particular case the action id is org.freedesktop.login1.reboot so if you run:

pkaction --action-id org.freedesktop.login1.reboot --verbose

the output should be something like:

org.freedesktop.login1.reboot:
  description:       Reboot the system
  message:           Authentication is required for rebooting the system.
  vendor:            The systemd Project
  vendor_url:        http://www.freedesktop.org/wiki/Software/systemd
  icon:              
  implicit any:      auth_admin_keep
  implicit inactive: auth_admin_keep
  implicit active:   yes

Here, active: yes means the user in the active session is authorized to reboot the system (details about implicit authorizations on polkit page). You can check if your session is active with:

loginctl show-session $XDG_SESSION_ID --property=Active
Active=yes
  • 1
    that mean any program I run can reboot my machine without my permission? – osdamv Jul 17 '15 at 20:17
  • 1
    @osdamv - just like any program you run could rm -rf your user files... – don_crissti Jul 17 '15 at 20:29
  • 2
    @osdamv Note that you could run all programs you don't trust using sudo --user=jimmy where the user jimmy does not have the right to execute that polkit command... – Bakuriu Jul 18 '15 at 4:24

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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