代码改变世界

关闭图形界面下普通用户关机重启命令- 7.x - CentOS

2018-08-09 12:04  丨o聽乄雨o丨  阅读(464)  评论(0编辑  收藏  举报
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;
        }
    }
});
chmod 755 55-inhibit-shutdown.rules

不用重启,命令就会运行