Centos7/Redhat7 禁止普通用户关机/重启

Centos7/Redhat7 禁止普通用户关机/重启

# vim /etc/polkit-1/rules.d/55-inhibit-shutdown.rules

polkit.addRule(function(action, subject) {
    if (action.id.indexOf("org.freedesktop.login1.power-off") == 0 ||
        action.id.indexOf("org.freedesktop.login1.reboot") == 0) {
        try {
            // user-may-reboot exits with success (exit code 0)
            // only if the passed username is authorized
            polkit.spawn(["/usr/local/bin/user-may-reboot",
                          subject.user]);
            return polkit.Result.YES;
        } catch (error) {
            // Nope, but do allow admin authentication
            return polkit.Result.AUTH_ADMIN;
        }
    }
});

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页