How can I suspend/hibernate from command line?
How can I suspend or hibernate my laptop using command line, without installing additional software?
For Ubuntu 16.04, see this question: http://askubuntu.com/questions/777178/suspend-command-in-ubuntu-16-04 and its answer `systemctl suspend`
Traditionally ubuntu supported a fairly blunt method of suspend and hibernate. Neither would integrate well with other apps and sometimes not even work on some machines. The new method doesn't require root and notifies all applications listening for power events.
Starting with Ubuntu 16.04,
systemctlcall must be used (See Suspend command in Ubuntu 16.04)
See the answer here on this page from Adam Paetznick regarding the use of dbus. Ideally you would create a
~/bin/suspendshortcut/script that makes the use of this action easy.
For use over ssh, you should modify policykit rules as outlined by Peter V. Mørch
According to the Ubuntu Forum you can use the following commands:
pmi action suspend
pmi action hibernate
This requires that you install the powermanagement-interface package (not tested).
sudo apt-get install powermanagement-interface
I have also found the commands
sudo pm-hibernateto work on my netbook.
pm-suspend and pm-hibernate works for me and it's easy. Requires sudo but that's OK. (Found pmi idea before but installing a package to use suspend is well bad...)
doesn't work with my ubuntu 12.10. after `apt-get install powermanagement-interface`
*new method* is now broken see http://unix.stackexchange.com/questions/153099/debian-jessie-cannot-suspend-anymore
`sudo pm-suspend` works well but while waking up after doing so doesn't ask me for password. what should I do.
none of the above works, even with sudo rights. not the `pm-hibernate`, `pmi action hibernate`, not the `dbus` stuff. I am sad.
The gnome-friendly way is to use dbus.
dbus-send --system --print-reply \ --dest="org.freedesktop.UPower" \ /org/freedesktop/UPower \ org.freedesktop.UPower.Suspend
There are two advantages to this command over
It will lock your screen (upon resume) if you have that option selected in gnome.
It does not require root privilege, so it is easy to add it as a keyboard shortcut, for example.
As mentioned in the comments exchanging the
Suspendin the last line to
Hibernatecreates a hibernate command:
dbus-send --system --print-reply \ --dest="org.freedesktop.UPower" \ /org/freedesktop/UPower \ org.freedesktop.UPower.Hibernate
If the hibernation throws
Error org.freedesktop.UPower.GeneralError: not authorizedyour user might not be allowed to hibernate. Edit or create
/etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pklaso it contains the following section: (source)
[Re-enable hibernate by default] Identity=unix-user:* Action=org.freedesktop.upower.hibernate ResultActive=yes
This was tested on UbuntuGnome 14.04.
Note: This is basically the same as qbi's answer, but updated to work for newer versions of Ubuntu as well as including hibernate.
Your answer really should be first. It's non-root no-packages-to-be-installed gnome way of doing it. Like!
AFAIK there is another advantage: It allows other program to detect that suspend/resume happened and act accordingly (for example an IM to resume a network connection to a server).
While this is actually the right way to do it (tm), SSH users should take note of : http://askubuntu.com/questions/21586/how-can-i-configure-dbus-to-allow-ssh-user-to-suspend-server
To `Hibernate`, you can simply replace the last line with `org.freedesktop.UPower.Hibernate`
This works under KDE too, except it doesn't lock the screen. You can do that with `qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock`.
on my 13.10 it does work. however, the screen is *not* locked upon resume, even though in "Security and Privacy", "Require my password when waking from Suspend" *is* activated.
This may be gnome friendly but I can still tell (i.e. wifi/ethernet notification and no graphic glitch) it's not the same clean result than when I do it through the Unity GUI or in the case of my laptop through a hardware suspend button.
Didn't work for me (Gnome 3.12, Ubuntu 14.04). Seems the [UPower.Suspend] interface was removed, according to https://bugs.launchpad.net/ubuntu/+source/gnome-power-manager/+bug/554899
Suspend interface was moved to logind; http://askubuntu.com/questions/652978/
This did work for me under 14.04 Trusty, but just moved to 15.10 Wily and it no longer works.
firstly, screen locking is not done, and secondly, after each hibernate-resume, the wifi laggs about every other minute. totally unusable for me.
Please evaluate if this gnome-friendly method is not superceded by 'the new command of systemd' as indicated in (https://askubuntu.com/questions/777178/suspend-command-in-ubuntu-16-04)
If you want your computer to suspend in one hour because you want to go to bed listening to your favorite radio station, open terminal and type:
sudo bash -c "sleep 1h; pm-suspend"
and your computer will fall asleep in 1 hour. When you awake, it will have kept your open images and all your stuff.
You can replace
1hby what you want:
Si vous voulez juste que votre ordinateur se mette en veille dans une heure parce que vous voulez vous endormir en ecoutant votre radio préférée, ouvrez Terminal et tapez :
sudo bash -c "sleep 1h; pm-suspend"
et votre ordinateur s'endormira dans une heure. Quand vous vous réveillerez, il aura conservé en mémoire vos applications ouvertes.
Vous pouvez remplacer
1hpar ce que vous voulez:
hpour les heures,
mpour les minutes,
spour les secondes,
dpour les jours.
Si quieres suspender tu computadora en una hora porque quieres ir a dormir escuchando tu estación de radio favorita, tan solo abre el terminal y escribe:
sudo bash -c "sleep 1h; pm-suspend"
y tu computadora se quedará dormida en 1 hora. Cuando despiertes, allí habrán quedado abiertas tus imágenes y todas tus cosas.
1hpor lo que desees:
For Ubuntu 12.04 LTS and Ubuntu 13.04
To get Hibernation:
To get Suspend:
Yeah I think that package was not installed . look for those packages in synaptic.
Perfect, thanks the pm-suspend was exactly what I was after without having to install all the X related junk with the powermanagement-interface package. All that's needed to use pm-* is the the pm-utils package.
The drawback of this method is that if you are using the GUI, pm-suspend will NOT block your session, which can be insecure.
You can use the file
/sys/power/stateto do this. First find out what states are supported:
[email protected]:_> cat /sys/power/state standby mem disk [email protected]:~> echo -n mem > /sys/power/state # suspend to ram [email protected]:~> echo -n disk > /sys/power/state # suspend to disk
or via dbus:
# Suspend dbus-send --session --dest=org.gnome.PowerManager \ --type=method_call --print-reply --reply-timeout=2000 \ /org/gnome/PowerManager org.gnome.PowerManager.Suspend #Hibernate dbus-send --session --dest=org.gnome.PowerManager \ --type=method_call --print-reply --reply-timeout=2000 \ /org/gnome/PowerManager org.gnome.PowerManager.Hibernate
According to this entry in launchpad the above interface was removed. So it would not work anymore in Ubuntu.
First idea gives me: "bash: echo: write error: Invalid argument" Dbus idea gives output: "Error org.freedesktop.DBus.Error.UnknownMethod: Method "Suspend" with signature "" on interface "org.gnome.PowerManager" doesn't exist"
I added a small explanation to the `/sys/power/state`-thing. Furthermore the dbus method was removed from Ubuntu so it won't work anymore.
`$ sudo echo -n mem > /sys/power/state` - `bash: /sys/power/state: Permission denied`
This works great. For people having problems with this method when using sudo, the "pipe to file", aka ">" is running in your current shell, so it doesn't get super user privileges while your echo did. You'll need to use `sudo -i` first, or pipe to `sudo tee` like so: `echo mem | sudo tee /sys/power/state`
To shutdown a system (14.04) from the command line (or keyboard shortcut) use:
dbus-send --system --print-reply --dest="org.freedesktop.login1" /org/freedesktop/login1 org.freedesktop.login1.Manager.PowerOff boolean:true
I found this out by playing around with gdbus which can list the interfaces available:
To list the services available on the bus:
dbus-send --system --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames
To find the methods:
gdbus introspect --system --dest org.freedesktop.login1 --object-path /org/freedesktop/login1 --recurse
since 15.04 systemD is the standard init system so there is a new command to be used:
I'm using Xubuntu 15.04. The command `systemctl suspend` does suspend the computer, but it does not cause the screen to be locked, even though I've checked the "Lock screen when system is going for sleep" checkbox in Settings -> Power Manager -> Security. Anyone have any idea why?
Adam Paetznick's dbus-send answer didn't work as purported for me on lucid; the machine woke up unlocked, even though the gnome-power-manager is set to lock the screen on wake-up. I want the screen to be locked at wake-up, and found that the following does that:
$ gnome-screensaver-command --lock && pmi action hibernate
I imagine this does not depend on the gnome configuration, but I haven't tested that.
…which works in 15.10 Wily, and possibly Utopic and Vivid.
dbus-send --print-reply --system \ --dest=org.freedesktop.login1 \ /org/freedesktop/login1 \ org.freedesktop.login1.Manager.Suspend boolean:true
Helpfully this doesn't require sudo, unlike the
Here's how to put a remote machine in standby over ssh:
ssh -t 192.168.1.4 'sudo nohup &>/dev/null bash -c "(sleep 1; echo -n mem >/sys/power/state) &"' [email protected]'s password: [sudo] password for x: Connection to 192.168.1.4 closed.
/sys/power/state works in Ubuntu 13.10. pmi gives Dbus error.