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

by nixcraft · 3 comments

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.

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 3 comments… read them below or add one }

1 Jeff Gobel 09.18.08 at 3:31 pm

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

2 Johan 11.02.09 at 5:43 am

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.

3 Tarvy 01.15.10 at 5:11 pm

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.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post:

Next post: