
我想在 Ubuntu 中為特定用戶停用“shutdown”和“poweroff”CLI 命令。怎麼做?
答案1
如果您只是在命令列上,從 sudo/admin/wheel 群組中刪除使用者可能就足夠了shutdown
,poweroff
並且reboot
需要 root 權限。
如果我們談論桌面會話(或由登入管理員(例如 consolekit 或登入)處理的會話),這可能會變得更複雜一些。在這種情況下,請按照此處所述調整系統的 polkit 規則(如果不存在則建立它們):https://askubuntu.com/questions/93542/how-to-disable-shutdown-reboot-suspend-hibernate
但請確保您要限制的使用者沒有其他方法獲得 root 存取權限(即您還需要阻止他使用sudo
)。否則他可以覆蓋或更改這些設定。
編輯:有關新 JS 配置格式的最新範例,請參閱https://wiki.archlinux.org/index.php/Polkit#Disable_suspend_and_hibernate
如果您使用的是 systemd(對於 Ubuntu 來說可能不是),操作 ID 也可能不同(以 org.freedesktop.login1.xxx 開頭,而不是 org.freedesktop.consolekit.xxx 開頭)。有關登入操作的列表,請查看https://www.freedesktop.org/wiki/Software/systemd/logind/