K.Mandla's blog of Linux experiences

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.