shutdown 與 shutdown now - 以非 root 身分關閉系統

shutdown 與 shutdown now - 以非 root 身分關閉系統

我剛剛觀察到一些奇怪的事情。

以非特權使用者身分登入 archlinux 系統,我執行了shutdown.正如所料,它返回了Must be root.

令我驚訝的是,執行shutdown now它(顯然!)確實不是檢查目前使用者是否有root權限。它只是關閉機器。

我嘗試在 Plasma DE 的 tty 和終端中重現此內容。

tty 的螢幕錄製


我正在使用 4.2.2 核心和當前軟體包運行 Archlinux。

我不認為這與圖形使用者介面政策

tl;dr: 以非 root 身分關閉系統shutdown now

答案1

實際上不是我的答案——只是重新發布了一個答案,遺憾的是,該答案已因未知原因被刪除。

來源:http://web.archive.org/web/20151014220049/https://superuser.com/questions/985661/shutdown-vs-shutdown-now-shutting-down-system-as-non-root


在 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,這是允許非特權用戶的。

--https://superuser.com/users/255732/mariusmatutiae

相關內容