
答案1
實際上不是我的答案——只是重新發布了一個答案,遺憾的是,該答案已因未知原因被刪除。
在 Arch Linux 中,在某些情況下,您很可能會在沒有 root 權限的情況下關閉/重新啟動/休眠...您的電腦。
有關 Systemd 下電源管理的 Arch Linux Wiki 頁面狀態:
作為非特權用戶,polkit 對於電源管理是必要的。如果您位於本機 systemd-logind 使用者會話中且沒有其他會話處於活動狀態,則下列命令無需 root 權限即可執行:
systemctl 關閉電源
systemctl 重新啟動
systemctl 掛起
systemctl 休眠
要檢查您是否可以這樣做(IE,您已經安裝了 polkit,並且您的會話沒有中斷)您可以使用以下命令:
$ loginctl show-session $XDG_SESSION_ID --property=Active
Active=yes
在其他systemd
系統上,例如我的 Debian 8,儘管對此命令有相同的回复,但這是不可能的:
$ loginctl show-session $XDG_SESSION_ID --property=Active
Active=yes
$ systemctl reboot
==== AUTHENTICATING FOR org.freedesktop.login1.reboot ===
Authentication is required for rebooting the system.
Authenticating as: ,,, (myusername)
Password:
這表明polkit
在 Arch Linux 和 Debian 上預設設定是不同的。 Arch Linux 的人們看到了這一點sudo
,他們說,Polkit 上的 wiki 頁面:
Polkit 用於控制系統範圍的權限。它為非特權程序與特權程序進行通訊提供了一種有組織的方式。與 sudo 等系統相比,它不會向整個進程授予 root 權限,而是允許對集中式系統策略進行更精細的控制。
像往常一樣,YMMV。
至於shutdown now
,我的猜測是它是一個重定向到systemctl poweroff
,這是允許非特權用戶的。