Hide Suspend/Hibernate options from KDE menu

Hi,

In our local school we’re running a mix of OpenSUSE Leap 15.2 clients, and some 15.1 (which I haven’t upgraded yet).

How do I hide Suspend/Hibernate options from the KDE menu? I just spent a couple hours reading a variety of information on the subject. There seems to be much confusion and no clear, simple and authoritative answer.

Cheers from the cold South of France.

Create a file “/etc/polkit-1/rules.d/10-disable-suspend.rules” with the following content:

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

that will disable suspend and hibernate for all users.

Thanks for the detailed answer. I already gave this a try, and it works on some installations, though not on all. I’m a bit puzzled.

Check the journal for polkit. It lists the rules processed:


**erlangen:~ #** journalctl -b -u polkit.service  
-- Logs begin at Sun 2021-01-03 13:54:46 CET, end at Sat 2021-01-09 11:16:32 CET. -- 
Jan 09 09:21:30 erlangen systemd[1]: Starting Authorization Manager... 
Jan 09 09:21:30 erlangen polkitd[657]: Started polkitd version 0.118 
Jan 09 09:21:30 erlangen polkitd[657]: **Loading rules from directory /etc/polkit-1/rules.d**
Jan 09 09:21:30 erlangen polkitd[657]: **Loading rules from directory /usr/share/polkit-1/rules.d**
Jan 09 09:21:30 erlangen polkitd[657]: **Finished loading, compiling and executing 3 rules**
Jan 09 09:21:30 erlangen systemd[1]: Started Authorization Manager. 
Jan 09 09:21:30 erlangen polkitd[657]: **Acquired the name org.freedesktop.PolicyKit1 on the system bus**
Jan 09 09:21:41 erlangen polkitd[657]: **Registered Authentication Agent for unix-session:2 (system bus name :1.29 [/usr/lib64/libexec/polkit-kde-authentication-agent-1], object path /org/kde/PolicyKit1/AuthenticationAgent, locale de_DE.UTF-8)**
**erlangen:~ #**

Puzzling indeed…

I’ve used that polkit rule for quite some time on several openSUSE versions.

I’d initially check the rule you’ve created for a possible typographic error; or, better perhaps, copy the rule from one of the working installs.

Much more simple is to set

[Sleep]
AllowSuspend=no
AllowHibernation=no

in sleep.conf. The very reason for polkit is to differentiate between different users.