How too hot-key bind "shutdown"
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. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
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. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
How too hot-key bind "shutdown"
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.
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.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: How too hot-key bind "shutdown"
Code: Select all
shutdown -h now
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
Re: How too hot-key bind "shutdown"
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 : /
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 : /
Re: How too hot-key bind "shutdown"
Code: Select all
sudo visudo
Code: Select all
<your username> ALL=(ALL) NOPASSWD: /sbin/shutdown
Re: How too hot-key bind "shutdown"
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 : )
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 : )
Re: How too hot-key bind "shutdown"
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:
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.
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.
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
Code: Select all
man sudoers
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.
Re: How too hot-key bind "shutdown"
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?
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?
Re: How too hot-key bind "shutdown"
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.
Re: How too hot-key bind "shutdown"
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: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?
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 runvisudo 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).
Code: Select all
visudo -f /etc/sudoers
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
OK I was too late. Glad it was fixable anyway.