How to sleep and hibernate with two users without root password?

on my laptop running leap 15.5 and KDE I locked screen and I tried to perform sleep action but it doesn’t works, so, I tried to hibernate but it doesnt works too, I unlocked my screen and found this advice:


so I suspected that sleep action also didn’t work for the same reason.
first I think it is a bug that this advice doesn’t appear in the locked screen becouse who is locking should know that root password is requested.
second, is it possible to sleep and hibernate with multiple users without root password?

Yes, you will need to define polkit rule to do it. The easiest way on openSUSE is to use /etc/polkit-default-privs.local

echo "org.freedesktop.login1.hibernate-multiple-sessions yes" >> /etc/polkit-default-privs.local
echo "org.freedesktop.login1.suspend-multiple-sessions yes" >> /etc/polkit-default-privs.local
set_polkit_default_privs

Keep in mind that it will allow every user to suspend/hibernate, even if user is logged in remotely. You may consider auth_admin:yes:yes instead of plain yes to at least restrict it to locally logged in users. See man set_polkit_default_privs and man polkit-default-privs for details.

Well … the request is displayed by polkit authentication agent which runs as part of your user session. But the whole purpose of screen saver is to completely hide your session and show something else. To display this request on locked screen your screen saver needs to effectively implement polkit authentication agent internally (because nothing else can display anything while screensaver is running). So it is not exactly a bug, rather design problem and arguably missing functionality.

You may consider contacting support channels or bug tracker of the screen saver program you are using to at least start discussion.

manythanks, I did what you said me and after a reboot hibernate works with two users (I never used so recently hibernate to remember well, is it correct that when I press the ON button the GRUB appear to me? ) and choosing the correct voice in GRUB the two user sessions come up
but sleep doesn’t work with two users, it remain as if it was only locked, this is my file:

#
# /etc/polkit-default-privs.local
#
# This file is used by the set_polkit_default_privs tool to generate polkit
# rules. It is meant for local overrides of the active profile (defined in
# /etc/sysconfig/security) by the administrator of the system: any definitions
# here take precedence over the distribution defaults in
# /etc/polkit-default-privs.<profile>.
#
# The syntax for this file is defined in polkit-default-privs(5). Note that you
# need to run /sbin/set_polkit_default_privs for changes to take effect.

#2023-12-10dic-aggiunte da pla per permettere sleep e hibernate con multiutenti
org.freedesktop.login1.hibernate-multiple-sessions auth_admin:yes:yes
org.freedesktop.login1.suspend-multiple-sessions auth_admin:yes:yes

No idea. You could try checking logs for a start.

manythanks, I checked in yast /var/log/messages
looking for suspend and in the lasts rows I found this:
could be it useful or I have to check other?

2023-12-10T19:56:22.660137+01:00 plaST kernel: [  249.465176][ T2927] mei_pxp 0000:00:16.0-fbf6fcf1-96cf-4e2e-a6a6-1bab8cbe36b1: bound 0000:00:02.0 (ops i915_pxp_tee_component_ops [i915])
2023-12-10T19:56:22.662840+01:00 plaST kernel: [  249.466884][ T5800] done.
2023-12-10T19:56:22.665821+01:00 plaST systemd-sleep[5800]: System returned from sleep state.
2023-12-10T19:56:22.666054+01:00 plaST bluetoothd[1490]: Controller resume with wake event 0x0
2023-12-10T19:56:22.668046+01:00 plaST dns-dnsmasq.sh[5827]: <debug> NETWORKMANAGER_DNS_FORWARDER is not set to "dnsmasq" in /etc/sysconfig/network/config -> exit
2023-12-10T19:56:22.668109+01:00 plaST kernel: [  249.470129][ T5800] PM: suspend exit
2023-12-10T19:56:22.671038+01:00 plaST systemd-sleep[5832]: INFO: Skip running /usr/lib/systemd/system-sleep/grub2.sleep for suspend
2023-12-10T19:56:22.674662+01:00 plaST systemd[1]: systemd-suspend.service: Deactivated successfully.
2023-12-10T19:56:22.674976+01:00 plaST systemd[1]: Finished System Suspend.
2023-12-10T19:56:22.676385+01:00 plaST systemd[1]: Stopped target Sleep.
2023-12-10T19:56:22.676664+01:00 plaST systemd[1]: Reached target Suspend.
2023-12-10T19:56:22.677524+01:00 plaST systemd[1]: Stopped target Suspend.
2023-12-10T19:56:22.682581+01:00 plaST systemd-logind[910]: Operation 'sleep' finished.
2023-12-10T19:56:22.687690+01:00 plaST ModemManager[957]: <info>  [sleep-monitor] system is resuming
2023-12-10T19:56:25.223378+01:00 plaST ModemManager[957]: <info>  [base-manager] couldn't check support for device '/sys/devices/pci0000:00/0000:00:14.3': not supported by any plugin
2023-12-10T19:56:26.119697+01:00 plaST kded5[1973]: "Object does not exist at path “/org/freedesktop/NetworkManager/ActiveConnection/1”"
2023-12-10T19:56:26.119785+01:00 plaST kded5[3498]: "Object does not exist at path “/org/freedesktop/NetworkManager/ActiveConnection/2”"

According to this log your system did suspend (or at least attempted to suspend).

may be it suspended but suddenly resume, have you some suggestion on how to investigate?

Read earlier logs?

I checked if what I did in polkit was good,
I found this command but it seems that the insertion in /etc/polkit-default-privs.local
and the command /sbin/set_polkit_default_privs
didn’t worked.
is this command to check the permission in polkit action correct ?

pla@plaST:~> pkaction -v --action-id org.freedesktop.login1.suspend-multiple-sessions
org.freedesktop.login1.suspend-multiple-sessions:
  description:       Suspend the system while other users are logged in
  message:           Authentication is required to suspend the system while other users are logged in.
  vendor:            The systemd Project
  vendor_url:        https://systemd.io
  icon:              
  implicit any:      auth_admin_keep
  implicit inactive: auth_admin_keep
  implicit active:   yes
  annotation:        org.freedesktop.policykit.imply -> org.freedesktop.login1.suspend

pla@plaST:~> pkaction -v --action-id org.freedesktop.login1.suspend
org.freedesktop.login1.suspend:
  description:       Suspend the system
  message:           Authentication is required to suspend the system.
  vendor:            The systemd Project
  vendor_url:        https://systemd.io
  icon:              
  implicit any:      auth_admin_keep
  implicit inactive: auth_admin_keep
  implicit active:   yes

pla@plaST:~> 

No, it shows you the defaults from the action definition. The rules are JavaScript files so it is simply impossible to show “the current permissions” because they are computed when authorization is requested. You can use pkcheck to display what permissions would be computed for a given subject (usually some process).

To suspend you need swap with proper volume.