Howto: Shut down Linux from the Openbox right-click menu

This is kind of a weird problem with a lot of different solutions. Usually it’s a trick to shut down the computer from the right-click menu in Openbox if you’re using a privileged user account, not a root account. That’s because the right-click menu can’t spawn the password box needed to ask permission to shut down.

There are a couple of ways around that. You could use a third-party program like gksu, which is particularly suited to the task. The unfortunate part of using gksu is that, in Ubuntu, it’s marked as dependent upon a whole scrambled mess of Gnome packages. (Actually, the Arch version is too.) And as you know, I hate Gnome dependencies.

There are less elegant, but also effective, ways of doing this. If the command needs a reply from sudo, spawn it via a terminal. In other words, kick it through the menu like this.

xterm -e sudo halt

Simple enough: Start a terminal and if your password is needed, your next prompt should ask for it. Get it right and the shutdown sequence starts; get it wrong and life goes on.

On the other hand, if you just want to click a button and shut down, then a password isn’t ideal. In that case, this method might be an improvement.

Edit /etc/sudoers (which technically you should do with the visudo command, but I don’t) and add this line at the bottom.

%users ALL=NOPASSWD: /sbin/halt

That allows everyone in the group “users” to issue the halt command without a password.

You should already have something like this in your sudoers file; if not, you might want to add it.

%wheel ALL=(ALL) SETENV: ALL

That’s the line that screens for proper sudo access to start with. In other words, if you’re not in the group “wheel”, you shouldn’t be able to run any systemwide command like halt.

Now add the command line to your Openbox menu, either through ObMenu or via direct editing. In either case, the actual command should just be …

sudo halt

Reconfigure Openbox, and that should allow you to shutdown without a password. (I don’t think you need a restart, but you might.) Note that this doesn’t mean you can run sudo without a password at all; other commands should still be screened normally.

It’s worth noting that this method should work for other window managers with editable menus — like JWM and others.

2 Responses to “Howto: Shut down Linux from the Openbox right-click menu”


  1. 1 billy October 29, 2007 at 2:09 am

    Thank you, KMandla. Is there a reason why you use halt instead of ’shutdown -h now’ (and ’shutdown -r now’ for reboot)? Is there any real difference?

  2. 2 K.Mandla November 12, 2007 at 10:19 am

    Not that I’m aware of. I prefer typing “halt,” because it’s shorter. ;)

Leave a Reply




Welcome!

Most recent desktop


May 8, 2008
XFCE 4.4.2 on Crux Linux
750Mhz Celeron 128Mb PC100

Most recent game

Gnome Mahjongg on Debian 550Mhz Celeron 192Mb PC100

Be counted!

License

This work is licensed under the GNU Free Documentation License. Please see the About page for details.

Blogs worth watching

Ubuntu Feeds

Blog Stats

  • 597,100 hits

Categories