Xubuntu suspend by commandline / keyboard shortcut

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
^rooker
Site Admin
Posts: 1483
Joined: Fri Aug 29, 2003 8:39 pm

Xubuntu suspend by commandline / keyboard shortcut

Post 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)
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
User avatar
peter_b
Chatterbox
Posts: 383
Joined: Tue Nov 12, 2013 2:05 am

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

Post 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.
Post Reply