boh*_*boh 6 linux shutdown reboot session-manager
为什么我需要以 root 身份从终端关闭/重新启动我的计算机?通过 GUI 菜单执行此操作不需要 root 权限。
小智 10
通常操作系统在启动时启动一个以 root 身份运行的服务,并为桌面环境提供一些有关计算机的可能性。通常它是 ConsoleKit 或 systemd-logind。
例如,在 KDE 中,您可以以普通用户的身份从命令行关闭计算机,例如:
qdbus org.kde.ksmserver /KSMServer logout 0 0 0
Run Code Online (Sandbox Code Playgroud)
这是可能的,因为 KDE 会话管理器将联系shutdown以 root 身份运行的 DBus 服务,并且在调用时将以root 权限运行命令。
在运行 ConsoleKit 的系统上,您可以使用:
gdbus call -y -d org.freedesktop.ConsoleKit \
-o /org/freedesktop/ConsoleKit/Manager \
-m org.freedesktop.ConsoleKit.Manager.Stop
Run Code Online (Sandbox Code Playgroud)
在使用systemd-logind 的系统上,该shutdown实用程序已经使用 DBus 并且不需要特权。
总而言之,您可以以普通用户身份关闭计算机,因为桌面环境运行的服务提供了以 root 身份运行 shutdown[1] 命令的可能性。
[1] 实际上,该服务会执行其他操作以确保桌面环境正确关闭。
| 归档时间: |
|
| 查看次数: |
1821 次 |
| 最近记录: |