需要 sudo 密碼才能關閉一個會話

需要 sudo 密碼才能關閉一個會話

我有一台運行 Ubuntu 的計算機,可供多人使用。它花費大量時間關閉電源。有時,我想使用 LAN 喚醒來啟動它,透過 ssh 連線並在背景啟動作業。我不希望電腦在該作業運作時關閉。

然而,由於有多個人可能使用這台電腦,有人可以走到機器前,登錄,檢查他們的電子郵件或其他什麼,然後關閉電腦。或者,有人可能會注意到它已打開並顯示 GDM 登入螢幕,並決定將其關閉。

有沒有辦法防止這種情況發生?它不必讓它完全不可能:只需讓計算機彈出一個窗口,顯示“您真的確定(作業正在後台運行)嗎?”會做得很好。但是,它必須在登入後的 Gnome 選單和 GDM 螢幕上都可以工作。

答案1

您可以在 GDM 中停用它,也可以在登入後從選單中停用它。

編輯/usr/share/polkit-1/actions/org.freedesktop.consolekit.policy以及它所說的地方

<allow_active>yes</allow_active>

將其更改為

<allow_active>auth_admin_keep</allow_active>

所以該文件將如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
 "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">

<!--
Policy definitions for ConsoleKit
-->

<policyconfig>

  <action id="org.freedesktop.consolekit.system.stop">
    <description>Stop the system</description>
    <message>System policy prevents stopping the system</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>no</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>no</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.consolekit.system.restart">
    <description>Restart the system</description>
    <message>System policy prevents restarting the system</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>yes</allow_active>
    </defaults>
  </action>

</policyconfig>

筆記:你不更改最後兩部分(它們影響重新啟動),但我假設如果您不希望有人關閉計算機,那麼您也不希望他們重新啟動計算機。

為了更快地完成此操作,您可以建立該檔案的兩個版本(一種允許普通用戶關閉計算機,一種不允許)在您的主目錄中的某個位置,並有一個腳本將其中一個複製到 /usr/share/polkit-1/actions/.

答案2

對於 gdm,我認為有一種方法可以停用系統控制,但我不知道如何。對於 gnome,您可以使用命令“gksudohalt”建立啟動器。如果您想關閉計算機,它會詢問密碼。

相關內容