如果还有其他用户通过ssh登录,则禁用shutdown / suspend


15

我记得在9.04左右的ubuntu版本中,如果有其他用户登录,可能会禁用用户关闭系统(甚至可能也挂起),例如policykit之类的东西。

在11.04中可以做吗?

谢谢

编辑:

如果有人需要(出于自担风险),则/ usr / lib / pm-utils / bin / pm-action中的少量更改将允许用户在只有用户登录的情况下或者当用户将运行sudo pm-suspend时挂起计算机。可能不是最好的代码,但目前可以使用。

diff -r 805887c5c0f6 pm-action
--- a/pm-action Wed Jun 29 23:32:01 2011 +0200
+++ b/pm-action Wed Jun 29 23:37:23 2011 +0200
@@ -47,6 +47,14 @@
    exit 1
 fi

+if [ "$(id -u )" == 0 -o `w -h | cut -f 1 -d " " | sort | uniq | wc -l` -eq 1 ]; then
+                echo "either youre root or root isnt here and youre only user, continuing" 1>&2
+                else
+                echo "Not suspending, root is here or there is more users" 1>&2
+                exit 2
+                fi
+
+
 remove_suspend_lock()
 {
    release_lock "${STASHNAME}.lock"

问题仍然存在,当有多个用户登录时(不重写pm-suspend或暂停(或其他黑客)),是否可以禁止关闭或暂停?

Answers:


1

更新(感谢enzotib):

我在原来的答复中列出的文件应该被编辑,作为一个包更新可能会覆盖您的更改。

相反,应使用放置在中的配置文件来配置PolicyKit /var/lib/polkit-1/localauthority/,如pklocalauthority手册页中所述。

原始答案:

随着HAL的弃用,现在可以在 /usr/share/polkit-1/actions/org.freedesktop.consolekit.policy

设置allow_active在下方所示的两个动作段no(它们被设置为auth_admin_keep默认):

  <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>no</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>no</allow_active>
    </defaults>
  </action>

1
您应该/var/lib/polkit-1/localauthority/*.d按照pklocalauthority手册页中的说明在一个目录中设置策略文件。避免修改包安装的文件(如/usr/share/polkit-1/actions/org.freedesktop.consolekit.policy),而不是中的配置文件/etc/
enzotib

@scottl您可以编辑答案以正确阅读吗?正如现在所读,这完全令人困惑。
豪尔赫·卡斯特罗
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.