如何让关机不需要管理员密码?

Isa*_*iah 51 administration shutdown

如果超过一个人登录我的电脑,Ubuntu在关闭电脑时需要超级用户身份验证。我怎样才能让任何用户都可以在不要求输入密码的情况下关闭计算机?

Fli*_*imm 37

Richard Holloway 的回答实际上并不是授予 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
Run Code Online (Sandbox Code Playgroud)

然后.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
Run Code Online (Sandbox Code Playgroud)

参考:

  • 请注意,名称现在已更改!这是从 14.04: /usr/share/polkit-1/actions$ grep multiple * org.freedesktop.login1.policy: <action id="org.freedesktop.login1.power-off-multiple-sessions"> org.freedesktop .login1.policy: <action id="org.freedesktop.login1.reboot-multiple-sessions"> org.freedesktop.login1.policy: <action id="org.freedesktop.login1.suspend-multiple-sessions"> org .freedesktop.login1.policy: <action id="org.freedesktop.login1.hibernate-multiple-sessions"> (6认同)
  • 对于 16.04,除了 @Konstigt 的更改之外,对我来说,文件必须在 `/var/lib/polkit-1/localauthority/50-local.d` 中,并且两个文件都需要附加行 `ResultAny=yes` . 我现在得到的唯一警告消息是“无法设置墙消息,忽略:需要交互式身份验证。”,但现在关闭和重新启动工作正常。 (4认同)

Ric*_*way 29

您不需要解决方法,只需更改策略以允许您在多个用户登录时无需以管理员身份进行关机和重启即可关机。

使用您喜欢的文本编辑器编辑文件 /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>
Run Code Online (Sandbox Code Playgroud)

  <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>
Run Code Online (Sandbox Code Playgroud)

以及与其他人登录时重新启动有关的部分

  <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>
Run Code Online (Sandbox Code Playgroud)

  <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>
Run Code Online (Sandbox Code Playgroud)

这将允许您在多个用户登录时关闭并重新启动 PC。是否要这样做是一个不同的问题。

  • 重新安装或升级 polkit 时,您的更改不会被清除吗? (5认同)
  • @Ryan,根据 https://wiki.ubuntu.com/SecurityTeam/PolicyKitPermissions/12.04,您可以在 /etc/polkit-1/localauthority 中编写一个 .pkla 文件,但我不确定它的语法:)(有些这里的信息 https://wiki.archlinux.org/index.php/PolicyKit#Authorities) (3认同)

ibu*_*law 16

有个更好的方法。如果您安装了 dbus-send,您可以通过 dbus 关闭,而无需升级到 root 权限

我不记得文档所在的页面,但一位 Archlinux 用户发现了这一点。

关掉:

dbus-send --system --print-reply --dest=org.freedesktop.Hal \
          /org/freedesktop/Hal/devices/computer \
          org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown
Run Code Online (Sandbox Code Playgroud)

重启:

dbus-send --system --print-reply --dest=org.freedesktop.Hal \
          /org/freedesktop/Hal/devices/computer \
          org.freedesktop.Hal.Device.SystemPowerManagement.Reboot
Run Code Online (Sandbox Code Playgroud)

暂停:

dbus-send --system --print-reply --dest=org.freedesktop.Hal \
          /org/freedesktop/Hal/devices/computer \
          org.freedesktop.Hal.Device.SystemPowerManagement.Suspend int32:1
Run Code Online (Sandbox Code Playgroud)

休眠:

dbus-send --system --print-reply --dest=org.freedesktop.Hal \
          /org/freedesktop/Hal/devices/computer \
          org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate
Run Code Online (Sandbox Code Playgroud)

问候。


Epe*_*eli 12

HAL 现在似乎已弃用,并且未安装在最新的 Ubuntu 版本中。

您必须使用ConsoleKitUPower dbus 服务来管理电源状态

关掉:

dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop
Run Code Online (Sandbox Code Playgroud)

重新开始:

dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart
Run Code Online (Sandbox Code Playgroud)

暂停:

dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend
Run Code Online (Sandbox Code Playgroud)

休眠:

dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Hibernate
Run Code Online (Sandbox Code Playgroud)

感谢 Arch Linux论坛

这现在在 Precise 和 Quantal 中有效,但不知道 Freedesktop 的重点似乎从 ConsoleKit 转移到 systemd 多久了。不知道 Canonical 是否在乎...


Kon*_*igt 7

这适用于 14.04。Flimm之前的 IMO 正确答案的更新变体。

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 
Run Code Online (Sandbox Code Playgroud)

把这个贴在里面:

[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
Run Code Online (Sandbox Code Playgroud)

  • 我必须在 Ubuntu 18.04 上将 `ResultActive` 替换为 `ResultAny` (3认同)