Centos7/Redhat7 禁止普通使用者關機/重啟

coisini_覔發表於2020-10-24

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;
        }
    }
});

相關文章