How can I suspend using a keyboard shortcut, without administrator privileges?

Solution 1:

For Ubuntu 15.04. and later you can use from the terminal

systemctl suspend

Then create a shortcut in the settings/keyboard app with the same command.

key-sortcut

Easy!

Reason: Ubuntu switched from upstart to systemd.

Solution 2:

  1. Install the powermanagement-interface package first, it provides the pmi command we will use to suspend.
    UPDATE: I looked at the source for pmi and the command it uses to suspend is:

    dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend
    

    If you can't install pmi, replace pmi action suspend with that command in the next step.

  2. Open up System -> Preferences -> Keyboard Shortcuts, click on Add and put pmi action suspend as the command.

    alt text

  3. Click on the newly created shortcut entry, and set the shortcut keys.

    alt text

Solution 3:

Same as above, but use this command instead:

dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 "org.freedesktop.login1.Manager.Suspend" boolean:true

Source: http://forum.ubuntu-fr.org/viewtopic.php?pid=16497311#p16497311

Solution 4:

With Ubuntu 16.04 LTS an newer I would suggest using systemctl instead because newer systems use systemd to control things.

The safe command to run is systemctl suspend which suspends the machine immediately unless some process is asking the system to stay powered (e.g. video player showing a movie, active CD burner, another logged in user doing anything, etc).

If you want to force suspend immediately and ignore all "inhibitors" simply add -i as explained by the output of the above command.

If you want to immediately lock the screensaver and suspend the system in all cases, you can run

loginctl lock-session && systemctl suspend -i

This is better than using raw dbus to send messages because using loginctl and systemctl avoids hardcoding any info about your screensaver or session manager.