32

Since the last update of Ubuntu 14.04, when I press the sleep button in my laptop, a pop-up window appears with "Authentication is required for suspending the system".

Password is not requested when closing the lid. However, this doesn't work when another monitor is plugged in.

Is there anything that can be set up (in sudoers or somewhere else) to avoid this password prompt?

Braiam
  • 69,302
arauzo
  • 1,108

2 Answers2

23
  1. In command line run:

    locate -b org.freedesktop.login1.policy
    

    The found file is

    /usr/share/polkit-1/actions/org.freedesktop.login1.policy
    
  2. In the file, near line

    <action id="org.freedesktop.login1.suspend">
    

    check these:

    <defaults>
        <allow_any>yes</allow_any>
        <allow_inactive>yes</allow_inactive>
        <allow_active>yes</allow_active>
    </defaults>
    

(Source)

Vedavrat
  • 364
  • 2
  • 8
  • For Ubuntu 15.10 (wily) such solution should work as well. – Vedavrat Nov 21 '15 at 09:54
  • 4
    It does not ask me for password anymore, but I do not remember doing anything and I have those lines to <allow_any>auth_admin_keep</allow_any> What do they mean? Is there any security concern with changing them to "yes"? – arauzo Nov 22 '15 at 21:19
  • Here I needed also to change <action id="org.freedesktop.login1.suspend-multiple-sessions">; – sdlins Nov 05 '16 at 16:30
  • Great answer. I also found a solution to other problems I had... Namely the system inhibitor not allowing the suspend for 15 seconds or so. – Beni Bogosel Nov 17 '16 at 11:51
  • 9
    Does any authoritative source really advise this? Files in /usr/share should not be edited; that prefix is intended for read-only files installed by packages and not modified by users. The proper way is to copy the file to another, equivalent location like /etc, where editing is allowed, then make changes there. It would also be preferable to explain why these changes fix the problem, i.e. what the original problem is - e.g. what the (in my case) previous value of auth_admin_keep means, and why it's not right. – underscore_d Nov 08 '17 at 19:40
  • 3
    According to Arch Linux wiki, editing the .policy files is NOT the correct way. – mja Jan 18 '18 at 09:42
  • Why do I need to do such a thing at all? Does this also occur on a fresh install, or is it fixed there? If it does occur there as well, how can they let this happen in an LTS release (24.04)? If it does not occur there, what you write here is clearly not the correct solution. – Albert Oct 04 '24 at 22:03
18

Using Polkit

Add yourself to users group by

sudo usermod -aG users "$USER"

You need to reboot your computer after the following steps.

1. Find out which version of Polkit is installed

You can check version of Polkit by: pkaction --version

2. If PolKit version >= 0.106

Just add a file /etc/polkit-1/rules.d/85-suspend.rules with:

polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.login1.suspend" &&
        subject.isInGroup("users")) {
        return polkit.Result.YES;
    }
});

And in Terminal, type:

sudo chmod 755 /etc/polkit-1/rules.d
sudo chmod 644 /etc/polkit-1/rules.d/85-suspend.rules

3. If PolKit version < 0.106

If PolKit version < 0.106, there are NO .rules files but only old .pkla and .conf files because those Polkit versions do not have the Javascript interpreter.

In this case, adding a file /var/lib/polkit-1/localauthority/50-local.d/50-enable-suspend-on-lockscreen.pkla with:

[Allow suspending in lockscreen]
Identity=unix-group:users
Action=org.freedesktop.login1.suspend
ResultAny=yes
ResultInactive=yes
ResultActive=yes

In bash, type:

sudo chmod 644 /var/lib/polkit-1/localauthority/50-local.d/50-enable-suspend-on-lockscreen.pkla

More about pklocalauthority

Using Power Manager settings (not sure if it works)

In XFCE Power Manager:

  1. Under the Security tab:
  • Set Automatically lock the session to Never
  • Check Lock the screen when the system is going for sleep
  1. Under the Display tab, blank the screen after 15 minutes. Set Sleep and Switch off times to be disabled (greyed out).
  2. Under the System tab, set system sleep mode to Suspend after an half of hour.

References:

mja
  • 1,039