Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Xubuntu 12.04. In the Power Manager, I have checked Extended -> Lock screen when going for suspend/hibernate. If I choose to suspend from the main menu / Panel 1, the screen is locked. However, if I use dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend (see How can I suspend/hibernate from command line?; I use this command via a keyboard shortcut), the screen is not locked. How can I (1) suspend the system (2) have the screen locked at the same time (3) do not require root rights to do so [since I would like the command to be assigned to a keyboard shortcut].

share|improve this question
up vote 10 down vote accepted

You can do that by using the following:

gnome-screensaver-command --lock && dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend

In a keyboard shortcut you need to put sh -c "<command>" replacing <command> with the command above, like:

sh -c "gnome-screensaver-command --lock && dbus-send --system --print-reply --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend"

If the above command does not work, you can also try using a shell script file (for example First create the file call the following commands in a console:

cd ~
echo "gnome-screensaver-command --lock" >>
echo "dbus-send --system --print-reply --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend" >>
chmod +x

That will create a file named in the user home folder. Then, in the shortcut just call: ./

Note: gnome-screensaver-command can be replaced by xscreensaver-command, as pointed out in one comment.

share|improve this answer
Nope it does only lock the screen and forgets about suspending it according to a comment made in the answer I made ;) – Rinzwind May 17 '12 at 23:20
Ahh, good. I just realized that gnome-screensaver-command can also be replaced by xscreensaver-command so no additional installation is required. Without the && dbus-send... part one simply gets a lock (without suspend); with it, one gets a suspend with lock on wake-up. Perfect. – Marius Hofert May 17 '12 at 23:34
Unfortunately, the command works from the terminal but not from the keyboard shortcut I defined :-( Do you know what might be the problem? – Marius Hofert May 17 '12 at 23:41
@MariusHofert I've updated the answer with how to use the commands from a keyboard shurtcut. See if it works as you need. (I've tested in Ubuntu 12.04 and it worked). – amfcosta May 18 '12 at 14:06
Still the same problem: locking works; suspending does not (Xubuntu 12.04) – Marius Hofert May 18 '12 at 18:36

I was using amfcosta's dbus command to suspend from the command line. However, upon resume, eth0 was down.

I then found this command:

xfce4-session-logout --suspend

This command disables networking, suspends, and then re-enables networking when the computer wakes up.

xfce4-session-logout is xfce specific, but other desktop environments may have similar *-session-logout commands.

I am running Xubuntu 14.04.

Update: This may not affect others, but it turns out that on my Asus EEE 900, the wired ethernet connection only works every other time the EEE wakes up. This is, of course, very annoying, and means that suspend is unusable.

share|improve this answer

With Ubuntu 15.10, this works as well:

gnome-screensaver-command --lock && systemctl -i suspend
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.