Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Suspend, hibernate, restart or shutdown the computer without sudo!
# Suspend, hibernate, restart or shutdown the computer without sudo!
# by Chris Wong
# Released to the public domain.
usage() {
echo "Usage: $NAME suspend|hibernate|restart|shutdown"
exit 42 # :D
if [ $# -ne 1 ] ; then
THINGY_UPOWER="dbus-send --system --print-reply --dest=org.freedesktop.UPower /org/freedesktop/UPower"
THINGY_CONSOLEKIT="dbus-send --system --print-reply --dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager"
case $1 in
$THINGY_UPOWER org.freedesktop.UPower.Suspend
$THINGY_UPOWER org.freedesktop.UPower.Hibernate
$THINGY_CONSOLEKIT org.freedesktop.ConsoleKit.Manager.Restart
$THINGY_CONSOLEKIT org.freedesktop.ConsoleKit.Manager.Stop
Copy link

tenleftfingers commented Jan 16, 2013

Requires authentication as of Ubuntu 12.04.

Copy link

lambda-fairy commented Jan 24, 2013

@tenleftfingers I'm using 12.04 right now, and I've never had to authenticate. It should act as though you chose the corresponding option in the GUI. Screenshot?

Copy link

chyl commented Mar 5, 2013

I have the same authorization problem:

Error org.freedesktop.ConsoleKit.Manager.NotPrivileged: Authorization is required

I'm trying to resolve this but with no success.

Copy link

linuxuser600 commented Sep 9, 2015

I know this is a few years old but the script still works great. As an FYI for anyone who is using this script make sure you make the .sh file executable by going to the directory in the terminal and typing sudo chmod +x It will not work and will "Require Authentication" if you do not.

Copy link

lambda-fairy commented Oct 30, 2015

On machines with systemd, systemctl {suspend|hibernate|reboot|poweroff} works as well.

Copy link

ghost commented Apr 18, 2019

Error org.freedesktop.ConsoleKit.Manager.NotPrivileged: Not Authorized

Copy link

Pennino13 commented Dec 28, 2020

Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.ConsoleKit was not provided by any .service files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment