How to prevent GUI based Shutdown

With the proliferation of remote and cloud based workstations, should a user accidentally click Poweroff instead of Restart or Logout, it isn’t as easy as bending over and pressing Power button. So here you go. Makes the Poweroff GUI do nothing, but you can still Restart and Logout.

/etc/polkit-1/rules.d/10-block-shutdown.rules

polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.login1.power-off" ||
        action.id == "org.freedesktop.login1.power-off-multiple-sessions") {
        return polkit.Result.NO;
    }

    if (action.id == "org.freedesktop.login1.reboot" ||
        action.id == "org.freedesktop.login1.reboot-multiple-sessions") {
        return polkit.Result.YES;
    }
});

reboot.

5 Likes

Nice @ALan thanks

Rocky Linux i presume

1 Like