81

How can I set up a keyboard shortcut that I can use instead of clicking this menu item?

Suspend

I have read about various terminal commands for suspending which I could easily assign to a keyboard shortcut, but all have required the use of sudo. I am looking for a solution that I can use on a system where I do not have administer privileges.

1
  • There's a built in shortcut alt+shift+s. Validated on 22.04.3 but I think it exists for a very long time now. Aug 19, 2023 at 7:00

6 Answers 6

81

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.

7
  • 3
    Tested under 16.04
    – Elder Geek
    Aug 19, 2016 at 16:17
  • In 17.10, it's Settings -> Devices -> Keyboard.
    – colan
    Dec 31, 2017 at 19:55
  • 4
    It might be better to use Super + s as shortcut instead of Ctrl + S which is often used for saving the currently opened document. Nov 21, 2018 at 12:22
  • 7
    Still working on 20.04.
    – Giszmo
    Sep 2, 2020 at 19:44
  • 1
    Still working on 22.04
    – zvi
    Jan 31, 2023 at 17:05
31
  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

5
  • 5
    On Precise I had to apt-get install hal but working nicely now.
    – Cas
    Aug 10, 2012 at 22:16
  • 6
    Doesn't work for me in 14.04
    – metakermit
    Aug 9, 2014 at 12:44
  • 1
    found the answer on this question, using the full command for suspend as the shortcut action, on Ubuntu 15.10 askubuntu.com/questions/454039/…
    – Nick
    Jan 29, 2016 at 11:15
  • 2
    Suspend command that worked for me on 16.04 LTS was dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 "org.freedesktop.login1.Manager.Suspend" boolean:true Apr 4, 2017 at 3:17
  • @MaxGoodridge awesome! Oddly enough .Hibernate instead of suspend requires root...
    – Ufos
    Jun 15, 2018 at 14:17
9

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

3
  • 4
    This really should be an edit.
    – muru
    Oct 28, 2014 at 23:27
  • This is the only thing that works for me on 19.10
    – djboris
    Dec 13, 2019 at 19:18
  • 1
    Works for me on 20.04.
    – Giszmo
    Sep 2, 2020 at 19:39
4

systemctl suspend -i worked for me.

Mapped to super+d in the Keyboard settings custom shortcuts.

2

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.

0

Here a exaple how to create keyboard shortcut to suspend the system by pressing <Super> + s keys:

gsettings set org.gnome.settings-daemon.plugins.media-keys suspend "['<Super>s']"

or create a custom keybinding:

gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/']"
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ name 'suspend'
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ command 'systemctl suspend'
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ binding '<Super>p'

You must log in to answer this question.

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