系统相关
首页 > 系统相关> > linux – 当其他用户登录时,如何在Debian xfce中阻止关机或重启

linux – 当其他用户登录时,如何在Debian xfce中阻止关机或重启

作者:互联网

我想阻止用户在其他用户登录时开始关机或重启.用户可以是TTY用户(Ctrl Alt F3)或来自客户端主机的ssh用户.

在OpenBSD中,我将polkit org.xfce.session.policy与规则文件一起使用以防止此类操作.

我需要在Debian Testing(又名Buster)中找到如何做到这一点.
我找到了带有操作的org.freedesktop.login1.policy

> org.freedesktop.login1.power-off
> org.freedesktop.login1.power-off-multiple-sessions.

并为这些操作制作了规则文件,但它不会阻止关闭或重新启动.
在我看来,polkit对这些行为不负责任.

我不知道在哪里寻找这个;也许是systemd或PAM?

编辑

在OpenBSD和NetBSD上,默认情况下,不允许任何人从GUI关闭或重新启动.
您必须在/usr/local/share/polkit-1/rules.d/中创建一个规则文件,如下所示:

polkit.addRule (function (action, subject) {
    if (action.id == "org.xfce.session.xfsm-shutdown-helper")
    {
        return polkit.Result.YES;
    }
});

在Debian上,默认情况下,所有用户都可以从GUI关闭或重新启动.
org.xfce.session.xfsm-shutdown-helper或org.freedesktop.login1.power-off没有规则文件.

我尝试使用return polkit.Result.NO添加我的规则文件;无济于事
在debian上,我使用lightdm和BSD,我使用xdm.

解决方法:

Debian测试Buster使用polkit 1.05,因此没有规则文件也没有js语法.
您必须使用旧的策略套件ini-style.
要防止用户在其他用户登录时启动关机或重新启动,
你必须在/etc/polkit-1/localauthority/50-local.d/中创建两个pkla文件

cat /etc/polkit-1/localauthority/50-local.d/Reject_All_Users_To_login1_power-off-multiple-sessions.pkla 
[Reject all users to use login1_power-off-multiple-sessions]
Identity=unix-user:*
Action=org.freedesktop.login1.power-off-multiple-sessions
ResultAny=no
ResultInactive=no
ResultActive=no

cat /etc/polkit-1/localauthority/50-local.d/Reject_All_Users_To_login1_reboot-multiple-sessions.pkla
[Reject all users to use login1_reboot-multiple-sessions]
Identity=unix-user:*
Action=org.freedesktop.login1.reboot-multiple-sessions
ResultAny=no
ResultInactive=no
ResultActive=no

但是,这还不够,因为xfce也会安装一个关闭或重启的动作
/usr/share/polkit-1/actions/org.xfce.session.policy.
您还必须在/etc/polkit-1/localauthority/50-local.d/中为此操作创建一个pkla文件.

cat /etc/polkit-1/localauthority/50-local.d/Reject_All_Users_To_Use_Xfce_Session_Policy.pkla 
[Reject all users to use xfce_session_policy]
Identity=unix-user:*
Action=org.xfce.session.xfsm-shutdown-helper
ResultAny=no
ResultInactive=no
ResultActive=no

标签:linux,systemd,pam,xfce,polkit
来源: https://codeday.me/bug/20190815/1661614.html