Shutdown Without Sudo From Your Terminal

Using dbus and ConsoleKit it's easy to power off your computer from the terminal. This is useful when you're not using a desktop like GNOME or Unity and you want to shutdown without superuser privileges.

dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop

Of course it's probably a good idea to create an alias for this rather long command.

alias turnoff='dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop'

For the sake of completeness you can also restart and suspend your computer using dbus and ConsoleKit.

To restart use:
dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart

To suspend use:
dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend

This was posted on Sun 30 Nov 2014 (4 years, 7 months ago) by Ryan McConville