1

I am using Ubuntu 20.04. I mean to setup a simple way to hibernate, for anyone with no knowledge of Ubuntu/terminal to be able to hibernate.

I tried first setting up systemctl hibernate, and a Settings -> Keyboard Shortcuts for it. Hibernating this way didn't work well.

So I went the pm-hibernate way (e.g., this). Now sudo pm-hiberante works well. So I mean to set up a shortcut for it. I tried assigning the following commands in Settings -> Keyboard Shortcuts, to no avail:

  1. sudo pm-hibernate
  2. echo <my_password> | sudo -S pm-hibernate (I am a sudoer). Besides the fact it didn't work, this is not a desirable way to do things, since my password becomes exposed, although in this case I could settle for that if need be.

How can I get this working?

Possible routes below. I am not certain how to materialize them, and which of them cannot overcome the need for sudo:

  1. Adding an entry for Hibernate in the Power Off/Log out menu, using pm-hibernate. Possibly the preferred alternative.
  2. Have systemctl hibernate to actually execute sudo pm-hibernate (and without requiring my password). I guess this would work transparently with the shortcut already assigned to systemctl hibernate.
  3. Allow for any user to pm-hibernate. As a purist, one would avoid this, although if it solves the issue, it is fine.
  4. Have the sudo pm-hibernate shortcut displaying a message box where one can enter the password.

Related:

  1. how to make linux prefer sudo pm-hibernate over systemctl hibernate as default?
  2. Menu for hibernate does not work, pm-hibernate does
  3. Force hibernate using hibernate instead of pm-hibernate
1

1 Answer 1

0

If you're looking for a keyboard shortcut method, one way to do this would be to use pkexec in a shell script. This will prompt for a password before executing.

Here's a rough shell script to call pm-hibernate via pkexec:

#!/bin/bash
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY pm-hibernate

This can be saved just about anywhere, so long as the file is accessible to every user account on the machine.

Once this is saved, set it to be executable with chmod +x and give it a test:

./nighty-night.sh

You should now be prompted for your password and, so long as the account is an authorised sudoer, the call to pm-hibernate will go forward.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .