Tuesday, July 25, 2006


A Keyboard Shortcut for the 'shutdown' Command, and Modifying the sudoers File

Some conclusions from studies of shutting down in Linux (Ubuntu).This is the second of two posts about shutdown.

Thanks to Cucisan and Metalheart for their help on the Ubuntu forums.

How to make a keyboard shortcut for shutdown
Love keyboard shortcuts.
By default, Dapper is shut down by clicking an icon on the desktop. So, a mouse is necessary. In addition, you go through an extra step, as a dialogue box pops up in response.

To get around that, can create a keyboard shortcut for the halt command, which shuts down the computer properly, namely, after closing the active apps (shutdown can't be used with metactity shortcuts).

As for the configuration of any other user-defined keyboard shortcut, launch the editor from the terminal (or with a keyboard shortcut...):

In the GUI:
apps>metacity>keybinding_commands: gksudo halt
Then, in the global_keybindings tab : [favourite_shortcut]

As explained by Cucisan, gksudo is required by the graphic environment. It means the same as sudo in the terminal.
Mind you don't use something already taken by the system. CTRL-s, for example, is set to 'save as'...

Getting rid of the password popup (making 'shutdown' available to an ordinary user, not su)
To bypass the need to put in a password, followed the following instructions by Vivek.

The need to provide a password stems from the requirement to have superuser privileges in order to carry out some commands.
One of those commands is 'halt'.
Allowing use of such restricted commands by ordinary users requires modifying the sudoers file. This is a dangerous tweak. Was really careless in handling this myself, and spent a while with my heart in my mouth.

Warning: modifying sudoers is dangerous, should only be done when necessary and after proper study of the topic.

Only the visudo command allows access to the 'sudoers' file.
Study man visudo.
It will help to know what to do if you get into real trouble with visudo, as I have. Please see Sweet Recovery Mode and its Uses.

Before you start, you need to know the absolute path to your command. This can be obtained by:


To open 'sudoers' (/etc/sudoers):

$ sudo visudo.

Do not open the file directly, or do anything else directly with it.
It is to be edited only with visudo.

Inside sudoers
At the bottom of the file or at the 'user privilege spefication', append:

your_user_name ALL= NOPASSWD: /sbin/halt

It is desirable, as usual to preced this with some comment:

#Allwing ordinary users to use 'halt' without a password.

Now, save. You will be asked to confirm saving to /etc/sudoers.tmp, not /etc/sudoers.
You should say 'y'. The .tmp file is only a temporary version to allow one final hurdle before modifying 'sudoers' for good. The visudo command will now parse the changes for any syntax errors.

If there are any, visudo will issue an error message and ask 'what now?'.
To this, only two answers should really be considered: 'e' (back to editing) or 'x' (exit without saving the changes).

In my hands, the above (NOPASSWD) line only accepts one user and one command at a time. Proceeding otherwise will not be picked up by the visudo parser, yet will not dispense the user from the password prompt.

If all's well, you'll get the prompt again.

And, you'll be able to shut down the computer from the keyboard, without being prompted for a password.
Not bad.

Brokersring.com - Learn how to turn $500 into $5,000 in a month!

[url=http://www.brokersring.com/]Make Money Online[/url] - The Secret Reveled with Binary Option

Binary Options is the way to [url=http://www.brokersring.com/]make money[/url] securely online
Post a Comment

Links to this post:

Create a Link

<< Home

This page is powered by Blogger. Isn't yours?