如果我的电脑上有多个用户登录,Ubuntu在关闭电脑时会要求超级用户进行身份验证。我该如何设置让任何用户都能在不需要密码的情况下关闭电脑?
Richard Holloway's answer实际上并不是PolickKit授权的正确方式。安装在/usr/share/polkit-1/actions
下的文件不应该被修改。相反,您应该修改/etc/polkit-1/localauthority/50-local.d/
下的权限。
以下是如何针对此问题进行操作:
创建一个名为/etc/polkit-1/localauthority/50-local.d/allow_all_users_to_shutdown.pkla
的文件,并使用sudoedit
进行编辑,使其看起来像这样:
[Allow all users to shutdown]
Identity=unix-user:*
Action=org.freedesktop.consolekit.system.stop-multiple-users
ResultInactive=no
ResultActive=yes
.pkla
的文件。可以使用任何以.pkla
结尾的名称,例如allow_all_users_to_restart.pkla
,并将其填充以下内容:[Allow all users to restart]
Identity=unix-user:*
Action=org.freedesktop.consolekit.system.restart-multiple-users
ResultInactive=no
ResultActive=yes
/var/lib/polkit-1/localauthority/50-local.d
目录下,并且两个文件都需要添加额外的一行ResultAny=yes
。现在我只会收到一个警告信息:“无法设置墙壁消息,忽略:需要交互式身份验证。”但是现在关机和重启功能正常运作。 - sigalorsysctl poweroff -i
需要org.freedesktop.login1.power-off-multiple-sessions
权限,所以我创建了一个单独的文件,其中包含相同的行,只是将Action=org.freedesktop.login1.power-off-multiple-sessions
添加进去。 - wickedchicken你不需要绕过,只需更改策略以允许您在多个用户登录时无需身份验证即可关闭和重启。
使用您喜欢的文本编辑器编辑文件 /usr/share/polkit-1/actions/org.freedesktop.consolekit.policy。您将需要root权限。
将与其他用户登录时关闭相关的部分更改为
<action id="org.freedesktop.consolekit.system.stop-multiple-users">
<description>Stop the system when multiple users are logged in</description>
<message>System policy prevents stopping the system when other users are logged in</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
到
<action id="org.freedesktop.consolekit.system.stop-multiple-users">
<description>Stop the system when multiple users are logged in</description>
<message>System policy prevents stopping the system when other users are logged in</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
</action>
<action id="org.freedesktop.consolekit.system.restart-multiple-users">
<description>Restart the system when multiple users are logged in</description>
<message>System policy prevents restarting the system when other users are logged in</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
到
<action id="org.freedesktop.consolekit.system.restart-multiple-users">
<description>Restart the system when multiple users are logged in</description>
<message>System policy prevents restarting the system when other users are logged in</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
</action>
dbus-send --system --print-reply --dest=org.freedesktop.Hal \
/org/freedesktop/Hal/devices/computer \
org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown
dbus-send --system --print-reply --dest=org.freedesktop.Hal \
/org/freedesktop/Hal/devices/computer \
org.freedesktop.Hal.Device.SystemPowerManagement.Reboot
dbus-send --system --print-reply --dest=org.freedesktop.Hal \
/org/freedesktop/Hal/devices/computer \
org.freedesktop.Hal.Device.SystemPowerManagement.Suspend int32:1
休眠:
dbus-send --system --print-reply --dest=org.freedesktop.Hal \
/org/freedesktop/Hal/devices/computer \
org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate
致敬。
HAL 似乎已经过时,并且在最新的 Ubuntu 发行版中没有安装。
您必须使用 ConsoleKit 和 UPower dbus 服务来管理电源状态
关机:
dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop
dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart
dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend
dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Hibernate
sudo mkdir -p /etc/polkit-1/localauthority/50-local.d
sudoedit /etc/polkit-1/localauthority/50-local.d/allow_all_users_to_shutdown_reboot_suspend.pkla
将此粘贴到内部:
[Allow all users to shutdown]
Identity=unix-user:*
Action=org.freedesktop.login1.power-off-multiple-sessions
ResultActive=yes
[Allow all users to reboot]
Identity=unix-user:*
Action=org.freedesktop.login1.reboot-multiple-sessions
ResultActive=yes
[Allow all users to suspend]
Identity=unix-user:*
Action=org.freedesktop.login1.suspend-multiple-sessions
ResultActive=yes
[Allow all users to ignore inhibit of shutdown]
Identity=unix-user:*
Action=org.freedesktop.login1.power-off-ignore-inhibit
ResultActive=yes
[Allow all users to ignore inhibit of reboot]
Identity=unix-user:*
Action=org.freedesktop.login1.reboot-ignore-inhibit
ResultActive=yes
[Allow all users to ignore inhibit of suspend]
Identity=unix-user:*
Action=org.freedesktop.login1.suspend-ignore-inhibit
ResultActive=yes
ResultActive
替换为ResultAny
。 - lights0123Action=org.freedesktop.login1.power-off
、Action=org.freedesktop.login1.reboot
和Action=org.freedesktop.login1.suspend
的块。 - klugerama在其他用户登录的情况下重新启动,除非打开一个终端窗口并以root身份输入reboot
命令,否则无法绕过超级用户密码提示:
sudo reboot
sudo
也会要求您输入密码。http://linux.byexamples.com/archives/315/how-to-shutdown-and-reboot-without-sudo-password/