How too hot-key bind "shutdown"

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read this

How too hot-key bind "shutdown"

Postby 3xOSC on Fri Dec 28, 2012 12:58 pm

Here is what I'm talking about:

I am trying to find out the command line for various "Gnome" menus and windows by going into the command line and listing them all. So for exampl when I type in "gnome-power-statistics" and hit enter I get exactly that window and it even shows up on the "System Resources".

Picture: http://i.imgur.com/w64iu.jpg

With "gnome-power-statistics" I can simply go to "Keyboard" -> "Shortcuts" and make myself a hotkey to bring this menu up.

My problem is that I can't find the one for the "Shutdown" one. I had to bring it up via the typical "Start Menu" and Click.

Here's a picture: http://i.imgur.com/V4MWX.jpg

What's worse is that it doesn't even show up in the "System Resources."

Can anyone help me figure out a way to bind the menu to a key? I'm lazy (like most programmers) I don't want to scroll my touchpad all the way to the bottom left, then click on the menu, then wait for it to pop up, then click on the damn thing then hit shutdown. I want to be able to just go "alt+shift+f4" + click. Done.
3xOSC
Level 1
Level 1
 
Posts: 23
Joined: Sun Sep 30, 2012 2:52 pm

Linux Mint is funded by ads and donations.
 

Re: How too hot-key bind "shutdown"

Postby viking777 on Fri Dec 28, 2012 1:09 pm

Code: Select all
shutdown -h now


should do it (although there are others).

Strange isn't it, I would soooooo much rather move my mouse to the shutdown menu and click whatever is necessary then type in Alt/Shift/F4 (or anything else) and I think that is because I am lazy. And you think you are lazy for the opposite reason :? Beats me :?:

The only difference I can see is that you used the word 'touchpad' and I used the word 'mouse'. I will agree that touchpads are dreadful - just buy a mouse and you can be as lazy as me :lol:
Fujitsu Lifebook AH532 Laptop. Intel i5 processor, 6Gb ram, Intel HD3000 graphics, Intel Audio/wifi. Realtek RTL8111/8168B Ethernet.Ubuntu12.10 (Unity), Mint14 (Cinnamon), Manjaro (Xfce).
Image
User avatar
viking777
Level 13
Level 13
 
Posts: 4916
Joined: Mon Dec 01, 2008 11:21 am

Re: How too hot-key bind "shutdown"

Postby 3xOSC on Fri Dec 28, 2012 2:46 pm

Thanks for the command.

It works when I type it into the terminal, but it asks for my root password. So it won't work as a hotkey because I have to be inputing the password everytime I want to shutdown, and by skipping the command line I would not have anywhere to type it into.

I sometimes can't use a mouse because I do a lot of my work on trains, places with no tables or a nice clean surface : /
3xOSC
Level 1
Level 1
 
Posts: 23
Joined: Sun Sep 30, 2012 2:52 pm

Re: How too hot-key bind "shutdown"

Postby viking777 on Fri Dec 28, 2012 3:02 pm

Code: Select all
sudo visudo


Add this line.

Code: Select all
<your username> ALL=(ALL) NOPASSWD: /sbin/shutdown


Obviously type your real username (without the arrows).
Fujitsu Lifebook AH532 Laptop. Intel i5 processor, 6Gb ram, Intel HD3000 graphics, Intel Audio/wifi. Realtek RTL8111/8168B Ethernet.Ubuntu12.10 (Unity), Mint14 (Cinnamon), Manjaro (Xfce).
Image
User avatar
viking777
Level 13
Level 13
 
Posts: 4916
Joined: Mon Dec 01, 2008 11:21 am

Re: How too hot-key bind "shutdown"

Postby 3xOSC on Sat Dec 29, 2012 8:35 pm

That worked beautifully, thank you sir.

If you don't mind me asking one more favor of you, could you please explain that one liner you told me to input.

I wish to learn more instead of blindly copying and pasting : )
3xOSC
Level 1
Level 1
 
Posts: 23
Joined: Sun Sep 30, 2012 2:52 pm

Re: How too hot-key bind "shutdown"

Postby viking777 on Sun Dec 30, 2012 5:53 am

OK. /etc/sudoers is the file that controls access to the sudo command. The first element specifies that you must be logged in with <your username> (to prevent any other users taking advantage of this extra access). The second element 'ALL' specifies that you can gain this permission from any machine (in case you log in remotely, but you can change this to your machines hostname if you wish - run cat /etc/hostname if you don't know it). The third element (ALL) specifies the users you are allowed to operate as (you could change this to root if you wanted - but ALL obviously included root - or in fact you could leave it out all together as it is really overridden by the fourth element). The fourth element 'NOPASSWD' specifies that you don't need to specify a password for the fifth element and the fifth element is the address of the shutdown command (or any other command you don't want to enter a password for).

If your username was Fred and your machines hostname was Wilma you could write it more briefly like this:

Code: Select all
Fred  Wilma = NOPASSWD: /sbin/shutdown


But last time I answered you I was just about to shut down so you got the longer version, I had to research the short version.

Code: Select all
man sudoers


Will give you all the information you could ever want to know (more than you want to know probably).

Incidentally I should mention that adding NOPASSWD to sudoers is considered a security risk in some cases. Although in this case for someone to break into you machine and steal your username just so they can shut the machine down doesn't seem to me like it is going to be of any value to anyone. But be careful if you use this technique with other commands.
Fujitsu Lifebook AH532 Laptop. Intel i5 processor, 6Gb ram, Intel HD3000 graphics, Intel Audio/wifi. Realtek RTL8111/8168B Ethernet.Ubuntu12.10 (Unity), Mint14 (Cinnamon), Manjaro (Xfce).
Image
User avatar
viking777
Level 13
Level 13
 
Posts: 4916
Joined: Mon Dec 01, 2008 11:21 am

Re: How too hot-key bind "shutdown"

Postby 3xOSC on Mon Dec 31, 2012 1:56 pm

Thank you.
3xOSC
Level 1
Level 1
 
Posts: 23
Joined: Sun Sep 30, 2012 2:52 pm

Re: How too hot-key bind "shutdown"

Postby mf205 on Tue Jan 01, 2013 5:13 am

I'm also interested in being able to use the shutdown command without entering my password. I tried editing sudoers as above, but I must have done something wrong: now whenever I issue sudo (including sudo visudo!) I get

sudo: parse error in /etc/sudoers near line 32
sudo: no valid sudoers sources found, quitting...
sudo: unable to initialise policy plug-in

How do I fix this?
mf205
Level 1
Level 1
 
Posts: 2
Joined: Tue Jan 01, 2013 4:45 am

Re: How too hot-key bind "shutdown"

Postby mf205 on Tue Jan 01, 2013 5:49 am

OK, I managed to fix it: just had to su root, and then visudo to remove the offending line. Don't really know what was wrong with the modification I made, or why visudo didn't pick it up, though.
mf205
Level 1
Level 1
 
Posts: 2
Joined: Tue Jan 01, 2013 4:45 am

Re: How too hot-key bind "shutdown"

Postby viking777 on Tue Jan 01, 2013 6:01 am

mf205 wrote:I'm also interested in being able to use the shutdown command without entering my password. I tried editing sudoers as above, but I must have done something wrong: now whenever I issue sudo (including sudo visudo!) I get

sudo: parse error in /etc/sudoers near line 32
sudo: no valid sudoers sources found, quitting...
sudo: unable to initialise policy plug-in

How do I fix this?


First of all you say a prayer to the computer gods that you have a backup of the file /etc/sudoers (it might be made automatically by visudo - not sure about that). If you do have a backup then replace the new file with the old one from a live cd. When you edit sudoers with visudo this is what is meant to happen:

visudo parses the sudoers file after the edit and will not save the
changes if there is a syntax error. Upon finding an error, visudo will
print a message stating the line number(s) where the error occurred and
the user will receive the "What now?" prompt. At this point the user
may enter "e" to re-edit the sudoers file, "x" to exit without saving
the changes, or "Q" to quit and save changes. The "Q" option should be
used with extreme care because if visudo believes there to be a parse
error, so will sudo and no one will be able to sudo again until the
error is fixed. If "e" is typed to edit the sudoers file after a
parse error has been detected, the cursor will be placed on the line
where the error occurred (if the editor supports this feature).


It should be foolproof - unless you pressed Q at any time. Your alternative would be to boot into recovery mode then a root shell and run

Code: Select all
visudo -f  /etc/sudoers


Which repairs the file.

If you can't work out how to do that you could copy my backup file which looks like this:

Code: Select all
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults   env_reset
Defaults   mail_badpass
Defaults   secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root   ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d


You might be able to insert that into /etc from a live cd.

OK I was too late. Glad it was fixable anyway.
Fujitsu Lifebook AH532 Laptop. Intel i5 processor, 6Gb ram, Intel HD3000 graphics, Intel Audio/wifi. Realtek RTL8111/8168B Ethernet.Ubuntu12.10 (Unity), Mint14 (Cinnamon), Manjaro (Xfce).
Image
User avatar
viking777
Level 13
Level 13
 
Posts: 4916
Joined: Mon Dec 01, 2008 11:21 am

Linux Mint is funded by ads and donations.
 

Return to Newbie Questions

Who is online

Users browsing this forum: Bing [Bot], MtnDewManiac and 25 guests