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.

About these ads

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


  1. 1 billy 2007/10/29 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 2007/11/12 at 10:19 AM

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

  3. 3 Sam 2008/05/19 at 10:09 AM

    billy, it’s really a matter of personal preference. Also, it depends on the system.

    For some reason, shutdown -h now only takes me to a login console, but poweroff turns off the computer.

    I used the NOPASSWD method.

  4. 4 Patrick 2008/12/09 at 5:48 AM

    All, on a minimal Hardy install I was unable to assign permissions as outlined in this article. Hope it helps someone else.

    %users ALL=(ALL) NOPASSWD: /sbin/halt

  5. 5 babouk 2009/04/15 at 2:50 AM

    Thank You for the useful little tutorial
    I did not know, how to halt my arch/fluxbox system without
    password …
    Now I put into my menu.
    I use it for halt and for reboot also …

  6. 6 vev 2009/07/14 at 9:35 PM

    Wouldn’t pressing the power off button on the pc case work too?
    I know you need acpi configured.
    Cheers


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Welcome!



Visit the Wiki!

Some recent desktops


May 6, 2011
Musca 0.9.24 on Crux Linux
150Mhz Pentium 96Mb 8Gb CF
 


May 14, 2011
IceWM 1.2.37 and Arch Linux
L2300 core duo 3Gb 320Gb

Some recent games


Apr. 21, 2011
Oolite on Xubuntu 11.04
L2300 core duo 3Gb 320Gb

Enter your email address to subscribe to this blog and receive notifications of new posts.

Join 405 other followers

License

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

Blog Stats

  • 3,961,025 hits

Archives


Follow

Get every new post delivered to your Inbox.

Join 405 other followers

%d bloggers like this: