Linux Desktop How to shutdown, restart or logoff gnome via command / Launcher

It is true that Gnome desktop provides nice facility to logoff, shutdown or restart computer with dialog. You can create a nice shortcut to avoid the GUI confirmation dialog box to speed up work.

(A) Shutdown computer
i) Right click on Desktop > Select Create Launcher
ii) Type the Command in text box “sudo /sbin/shutdown -h 0” and for rest of properties refer following figure:

iii) Click Close to save. Please note that only root will be able to shutdown system. However with the help of sudo it is possible that non-privileged can also shutdown the system (without password). Type following commands:
a) Login as root user

b) Type visudo command:
#visudo

c) Append following text of line, so that all commands will be excuted without password.
vivek localhost= NOPASSWD: /sbin/shutdown -h 0
vivek localhost= NOPASSWD: /sbin/reboot

By default, sudo requires that a user authenticate him or herself before running a
command. This behavior is modified with NOPASSWD flag i.e. shutdown and reboot command would allow user vivek run as root on the localhost as root without authenticating (password) himself

d)Save the file and replace command in above figure with sudo /sbin/shutdown -h now and close the dialog Launcher dialog box.

(B) Restart computer
i) Right click on Desktop > Select Create Launcher
ii) Type the Command in text box “sudo /sbin/restart” and for rest of properties refer following figure:

(C) Logoff Gnome

i) Right click on Desktop > Select Create Launcher
ii) Type the Command in text box “/usr/bin/gnome-session-save –kill” and for rest of properties refer following figure:

iii) Make sure you turnoff user logout dialog box. Type command OR Click on Applications > Desktop Preferences > Advanced > Sessions and clear the option box ‘Prompt on logout’ > Click close to save changes.

You can also use logoff script, to logoff KDE/Gnome desktop session. All these hacks should also work with FreeBSD or OpenSolaris desktop.

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
10 comments… add one
  • R.Sayce Feb 1, 2014 @ 22:34

    Had to comb through a lot of dreck on the net before I found this vein of gold, these nuggets of information. Thank you from a noobster

  • rishi Dec 9, 2011 @ 16:44

    thank u randuwe. I was looking for it.

  • Andrea Sep 28, 2011 @ 8:54

    Thanks for this post! I really needed it. I knew how to create launchers for shutdown and reboot, but not for logoff. I really miss that single multi-purpose button Gnome use to have.

  • randuwe Sep 23, 2011 @ 6:48

    hey, I know the easiest way to make a logout and shutdown launcher.
    first step is create launcher as usual, like right click any place on desktop
    then in command box, type “gnome-session-save –logout-dialog”
    without quote, this will launch the default logout dialog.
    and type “gnome-session-save –shutdown-dialog” without quote to show shutdown dialog.
    as you can see, this just can be done in gnome. so, make two launcher for logout and shutdown.

    thanks for your attention 🙂

  • jeet Sep 21, 2010 @ 16:22

    gnome-kill like based commands how to use and how to find things

  • a.k.van der tuin Aug 26, 2010 @ 12:52

    cannot remove shutdown dialog on screen

  • Maxime Jun 14, 2010 @ 21:39

    I wasn’t satified by the “sudo shutdown” because shutdown doesn’t require specific rights in desktop environnement. Therefore I’ve searched for something else and finally found these commands using dbus (working on ubuntu Lucid) :

    #shutdown
    dbus-send –system –print-reply –dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop

    #restart
    dbus-send –system –print-reply –dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart

  • Tarvy Jan 15, 2010 @ 17:11

    Hey thanks for all the usefull info,

    In this article, for the restart command first say you say to type “sudo /sbin/restart”; But then the picture says “sudo /sbin/reboot”, On Intrepid I checked my sbin file to wich one exists and only the reboot command(application) was there.

    I still found what i was looking for though, and hope you will fix that so others dont mess up.

  • Johan Nov 2, 2009 @ 5:43

    With Gnome in OpenSuse 11.1 the shutdown dialog lets you only logout to single user mode instead of shutting down. Seems like this tutorial is just the solution needed, thank you. I’ve found that “shutdown -P” also causes the system to switch to single user mode, while “shutdown -h” lets it shut down. Is there any way to change the behaviour of “shutdown -P” to actually power down? It only makes sense that the -P option should switch off the pc and Gnome most probably uses that as well.

  • Jeff Gobel Sep 18, 2008 @ 15:31

    I had trouble finding this information, and this really helped me out. Much appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.