0

When I type in systemctl suspend in the terminal, my pc goes into sleep mode with no issue. However, when I type in systemctl hibernate, it firsts prints this error

Failed to hibernate system via logind: Access denied 

And then asks for password saying hibernate.target needs authentication.

So, any idea how I can have systemctl hibernate have the same behavior as systemctl suspend?

SaTa
  • 946
  • 1
  • 15
  • 24
  • Did you try with root? I get the same error, and wonder why. It adds to the error: Failed to start hibernate.target: Unit hibernate.target is masked. – Timo Aug 05 '21 at 19:02
  • I tried with root back then. Here are the instructions I followed to make it work: https://askubuntu.com/a/1197965/889735. – SaTa Aug 07 '21 at 06:59
  • Related: [systemctl suspend, Call to Suspend failed: Access denied](https://unix.stackexchange.com/q/749708/209677). keyword: polkit – Pablo Bianchi Jul 03 '23 at 02:47

1 Answers1

0

I got same message with fresh installed Ubuntu 18.04 and 19.10. It's probably because you need privileges to execute systemctl hibernate. To solve it, I did:

    sudo visudo -f /etc/sudoers.d/hibernate

and added following line:

    %adm    ALL=NOPASSWD: /bin/systemctl hibernate, /usr/bin/systemctl hibernate

Note: My user is member of group adm. Alternatively you can add new group, add all relevant users to that group and replace %adm by %<your-group>.

I'm not sure this is best practice but it solved the issue for me.

Furthermore you need swap space (swap file or swap partition) of minimum size of your RAM in order to hibernate you computer.

EDIT: added -f parameter for visudo

A.Fi.
  • 1
  • 3
  • Thanks for the answer. I added these two lines to the same file to enable running it: `Cmnd_Alias HIBERNATE_SVC = /bin/systemctl hibernate` `%sudo ALL=(ALL) NOPASSWD: HIBERNATE_SVC` I still need to run it with `sudo` though but it does not need a password. – SaTa Jan 18 '20 at 13:06