Page 1 of 1

Xubuntu suspend by commandline / keyboard shortcut

Posted: Fri Oct 27, 2017 5:34 pm
by ^rooker
This HowTo explains how to be able to suspend a (X)ubuntu machine using a keyboard shortcut.
(That's super convenient. I loooove it! :D )

This method was tested on Xubuntu 12.04 and 16.04, but should work on all GNU/Linux distros that offer a shell-command for suspend.
You need to configure your user to be allowed to execute the supend command "pm-suspend" with superuser-rights, but without prompting for a password.

Therefore you need to configure the "sudo" configuration.
IMPORTANT: Never edit /etc/sudoers directly, but use "visudo":

Code: Select all

$ sudo visudo
Add a line to sudo config so that your user can suspend without requiring to enter a password.

Code: Select all

me ALL= NOPASSWD: /usr/sbin/pm-suspend
In this example the username is "me".

Now assign a keyboard shortcut for your window manager.
In XFCE this is done in "Settings > Keyboard > Application Shortcuts".
Add the following command:

Code: Select all

sudo pm-suspend
... and assign a keyboard shortcut as you like ;)

That's it!
You can now send your PC to sleep using a keyboard shortcut. 8)

Xubuntu suspend by commandline: "xfce4-session-logout"

Posted: Fri Oct 15, 2021 8:07 pm
by peter_b
I just realized this:
  • pm-suspend does *not* lock the screen.
  • For security reasons you *want* your screen locked for suspend.
  • Is it a bug? No. :oops: Locking is not pm-suspend's job.
  • Depending on the system (desktop) environment, locking is done by another program.
  • for XFCE4 that's: "xflock4"
===> To suspend properly in Xubuntu, use the command:

Code: Select all

xfce4-session-logout --suspend
This behaves identical to the graphical configuration.