You are not logged in.

#1 2008-09-04 00:19:17

Falcata
Member
From: Michiana
Registered: 2008-01-23
Posts: 501
Website

Shutdown and Reboot without going root

Is there a way I can use the reboot or poweroff commands without using sudo or root?  Or is this a bad idea?

Last edited by Falcata (2008-09-04 00:19:30)

Offline

#2 2008-09-04 01:18:56

dsr
Member
Registered: 2008-05-31
Posts: 187

Re: Shutdown and Reboot without going root

It's a very bad idea, but you could activate the setuid bit on /sbin/poweroff, /sbin/reboot, /sbin/halt, or /sbin/shutdown (type 'chmod u+s file'). What's the reason you want to do this? If it's just so you don't have to login as root every time, you can just use sudo. If you don't want to have to type sudo every time, I guess you could run visudo and give yourself permission to run, let's say, /sbin/shutdown without a password. Then create an alias in your .bashrc (or your shell's equivalent) such as 'alias shutdown="sudo shutdown"'.

Edit: I don't endorse using setuid to shutdown without root privileges. Do so at your own risk.

Last edited by dsr (2008-09-04 01:20:56)

Offline

#3 2008-09-04 03:04:36

rscholer
Member
From: Gelsenkirchen, Germany
Registered: 2008-07-03
Posts: 48

Re: Shutdown and Reboot without going root

Please read the manpage for shutdown. Everything is explained there (Under the Headline "Access Control").

Offline

#4 2008-09-04 03:33:07

dsr
Member
Registered: 2008-05-31
Posts: 187

Re: Shutdown and Reboot without going root

rscholer wrote:

Please read the manpage for shutdown. Everything is explained there (Under the Headline "Access Control").

+1

CTRL-ALT-DEL is a much safer method than setuid or passwordless sudo.

Offline

#5 2008-09-04 05:25:43

scarecrow
Member
From: Greece
Registered: 2004-11-18
Posts: 715

Re: Shutdown and Reboot without going root

What about adding your user to the "power" group, as suggested in the wiki?


Microshaft delenda est

Offline

#6 2008-09-04 05:34:42

monstermudder78
Member
Registered: 2008-05-18
Posts: 120

Re: Shutdown and Reboot without going root

I used

chmod +s /sbin/halt
chmod +s /sbin/reboot

to allow me to Reboot and Shutdown from the Openbox Menu.  Not sure if there is a better way but this worked like a CHAMP.:cool:

Offline

#7 2008-09-04 08:45:22

richs-lxh
Member
Registered: 2008-08-23
Posts: 76

Re: Shutdown and Reboot without going root

I would suggest using root to shutdown and reboot, but that's just my preference.
If (like me) you have a root terminal open on the desktop, it's just a simple case of:

Shutdown

shutdown -h now

Reboot

reboot

I use fluxbox and this works for me.

richs-lxh

Last edited by richs-lxh (2008-09-04 08:46:31)

Offline

#8 2008-09-04 11:58:32

muunleit
Member
From: Germany
Registered: 2008-02-23
Posts: 234

Re: Shutdown and Reboot without going root

How about this wiki-entry? smile
=> Allow_users_to_shutdown


"The mind can make a heaven out of hell or a hell out of heaven" -- John Milton

Offline

#9 2008-09-04 12:18:08

byte
Member
From: Düsseldorf (DE)
Registered: 2006-05-01
Posts: 2,046

Re: Shutdown and Reboot without going root

scarecrow wrote:

What about adding your user to the "power" group, as suggested in the wiki?

That won't help with 'reboot' or 'shutdown'. The group is only used by HAL which in turn is used by Xfce, for example.


1000

Offline

#10 2008-09-04 18:07:14

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: Shutdown and Reboot without going root

What's wrong with using sudo for shutting down ? The millisecond in which you gain root privileges before the system goes down is a security risk !? tongue


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#11 2008-09-04 18:22:48

Factory
Member
Registered: 2008-02-24
Posts: 108

Re: Shutdown and Reboot without going root

moljac024 wrote:

What's wrong with using sudo for shutting down ? The millisecond in which you gain root privileges before the system goes down is a security risk !? tongue

Even though it seems nit-picky, I do see where this becomes a viable situation. For example, if I don't want to give my friend root privileges, but I want to let him use my laptop and, sequentially, shut it down when he's done.

Offline

#12 2008-09-04 18:24:18

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: Shutdown and Reboot without going root

Factory wrote:
moljac024 wrote:

What's wrong with using sudo for shutting down ? The millisecond in which you gain root privileges before the system goes down is a security risk !? tongue

Even though it seems nit-picky, I do see where this becomes a viable situation. For example, if I don't want to give my friend root privileges, but I want to let him use my laptop and, sequentially, shut it down when he's done.

Pressing the power button is not good enough for your friend eh ? wink


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#13 2008-09-04 18:24:51

monstermudder78
Member
Registered: 2008-05-18
Posts: 120

Re: Shutdown and Reboot without going root

moljac024 wrote:

What's wrong with using sudo for shutting down ? The millisecond in which you gain root privileges before the system goes down is a security risk !? tongue

Or if you want shutdown in the menu sudo doesn't work right.  At least I couldn't get it to.

Edit: And what is the SECURITY risk for allowing someone to shutdown the computer?

Last edited by monstermudder78 (2008-09-04 18:27:32)

Offline

#14 2008-09-04 19:37:18

theringmaster
Member
From: Air Force
Registered: 2007-07-16
Posts: 581
Website

Re: Shutdown and Reboot without going root

to shut down via command line use "halt". That does a nice clean and normal shutdown.

to reboot, just use "reboot" as mentioned above.


Check me out on twitter!!! twitter.com/The_Ringmaster

Offline

#15 2008-09-04 20:01:49

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: Shutdown and Reboot without going root

monstermudder78 wrote:
moljac024 wrote:

What's wrong with using sudo for shutting down ? The millisecond in which you gain root privileges before the system goes down is a security risk !? tongue

Or if you want shutdown in the menu sudo doesn't work right.  At least I couldn't get it to.

Edit: And what is the SECURITY risk for allowing someone to shutdown the computer?

Funny, shutdown via sudo works alright in the openbox menu for me....

EDIT: Oh, I think I see what you meant. Why wouldn't you use the NOPASSWD for shutdown ?

Last edited by moljac024 (2008-09-04 20:02:23)


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#16 2008-09-04 20:29:04

liquibyte
Member
Registered: 2007-11-11
Posts: 91
Website

Re: Shutdown and Reboot without going root

edit /etc/shutdown.allow and add your username.

I created off an on in /usr/sbin.

#!/bin/bash
shutdown -h now
#!/bin/bash
shutdown -r now

off shuts me down and on reboots.  Simple eh?

Offline

#17 2008-09-04 21:21:36

monstermudder78
Member
Registered: 2008-05-18
Posts: 120

Re: Shutdown and Reboot without going root

moljac024 wrote:
monstermudder78 wrote:
moljac024 wrote:

What's wrong with using sudo for shutting down ? The millisecond in which you gain root privileges before the system goes down is a security risk !? tongue

Or if you want shutdown in the menu sudo doesn't work right.  At least I couldn't get it to.

Edit: And what is the SECURITY risk for allowing someone to shutdown the computer?

Funny, shutdown via sudo works alright in the openbox menu for me....

EDIT: Oh, I think I see what you meant. Why wouldn't you use the NOPASSWD for shutdown ?

Just so we are on the same page:  I wanted an entry on my openbox menu for reboot and shutdown so I could right-click the desktop and select reboot or shutdown.  When I set the menu command to "sudo shutdown" it worked as long as I had used sudo in a terminal in the last 5 minutes (or whatever the time limit is) but would just freeze if I hadn't used sudo recently.  My fix was to chmod +s halt and reboot, allowing the halt and rebnoot command to be executed from the menu.

My question:  What is the difference between 'chmod +s halt' and NOPASSWD for shutdown as you suggested?  I am not familiar with NOPASSWD.

Offline

#18 2008-09-04 21:29:30

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: Shutdown and Reboot without going root

[threadjack]
Can anyone offer a good explanation of the difference between "poweroff" and "shutdown -h now"? What exactly is the "safely" part of bringing down the system and is there a real reason to use "shutdown -h now" instead of using "poweroff" (which is faster)?


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#19 2008-09-04 22:42:59

mcmillan
Member
Registered: 2006-04-06
Posts: 737

Re: Shutdown and Reboot without going root

My question:  What is the difference between 'chmod +s halt' and NOPASSWD for shutdown as you suggested?  I am not familiar with NOPASSWD.

NOPASSWD is specified when you configure sudo, so some commands will be executed without asking for your users password. This is probably why it wasn't working for your menu, the computer was waiting for a password but there wasn't a way to display that request or enter it in.

Offline

#20 2008-09-04 23:06:58

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: Shutdown and Reboot without going root

mcmillan wrote:

My question:  What is the difference between 'chmod +s halt' and NOPASSWD for shutdown as you suggested?  I am not familiar with NOPASSWD.

NOPASSWD is specified when you configure sudo, so some commands will be executed without asking for your users password. This is probably why it wasn't working for your menu, the computer was waiting for a password but there wasn't a way to display that request or enter it in.

Exaclty. So you could specify the NOPASSWD parameter for the shutdown command and sudo will just do it without asking for the password. You should have an example of how to use that in your sudoers file. If not, then

man sudo

Last edited by moljac024 (2008-09-04 23:09:01)


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#21 2008-09-04 23:09:46

monstermudder78
Member
Registered: 2008-05-18
Posts: 120

Re: Shutdown and Reboot without going root

mcmillan wrote:

My question:  What is the difference between 'chmod +s halt' and NOPASSWD for shutdown as you suggested?  I am not familiar with NOPASSWD.

NOPASSWD is specified when you configure sudo, so some commands will be executed without asking for your users password. This is probably why it wasn't working for your menu, the computer was waiting for a password but there wasn't a way to display that request or enter it in.

That makes sense, and is in line with what I figured was going on.  With NOPASSWD which commands would be executed w/out asking for a password?  How would this be more "secure" than using chmod +s on halt and reboot?  It seems that both ways accomplish the same thing in the end, I am just trying to understand why one is better than the other.

moljac024 wrote:
mcmillan wrote:

My question:  What is the difference between 'chmod +s halt' and NOPASSWD for shutdown as you suggested?  I am not familiar with NOPASSWD.

NOPASSWD is specified when you configure sudo, so some commands will be executed without asking for your users password. This is probably why it wasn't working for your menu, the computer was waiting for a password but there wasn't a way to display that request or enter it in.

Exaclty. So you could specify the NOPASSWD parameter for the shutdown command and sudo will just do it without asking for the password. You should have an example of how to use that in your sudoers file. If not, then

man sudo

Please excuse my ignorance, but how is this better than chmod +s, which allows my user to use it w/out sudo?  It seems as though one lets ME use sudo w/out a password, the other lets ME use the command w/out sudo.  What is the benefit to using sudo without a password, other than not having to physically type the password?

Last edited by monstermudder78 (2008-09-04 23:13:40)

Offline

#22 2008-09-04 23:48:58

matahari
Member
From: Bandung, Indonesia
Registered: 2007-04-04
Posts: 59

Re: Shutdown and Reboot without going root

chmod +s -> every users can shutdown your machine
NOPASSWD -> depend how you configure sudo

Offline

#23 2008-09-05 00:01:31

chochem
Member
From: Denmark
Registered: 2008-03-02
Posts: 176
Website

Re: Shutdown and Reboot without going root

byte wrote:
scarecrow wrote:

What about adding your user to the "power" group, as suggested in the wiki?

That won't help with 'reboot' or 'shutdown'. The group is only used by HAL which in turn is used by Xfce, for example.

It would be a nice, clean solution though if there was, say a program that simply used the interface to put up a simple gtk shutdown menu... Adding yourself to a group rather than messing about with sudoers would be an improvement.

EDIT: I don't suppose there is a way to use the hal interfaces from the command line? Like gmount only for power settings?

Last edited by chochem (2008-09-05 00:17:31)

Offline

#24 2008-09-05 00:42:05

dsr
Member
Registered: 2008-05-31
Posts: 187

Re: Shutdown and Reboot without going root

Xyne wrote:

[threadjack]
Can anyone offer a good explanation of the difference between "poweroff" and "shutdown -h now"? What exactly is the "safely" part of bringing down the system and is there a real reason to use "shutdown -h now" instead of using "poweroff" (which is faster)?

Their command-line options differ, so you probably want to read the manpages, but I believe during normal operation (runlevel 3 or 5) the following is correct:

"shutdown -h now" is functionally the same as "poweroff" which is functionally the same as "halt -p" or just "halt"
"shutdown -r now" is functionally the same as "reboot" which is functionally the same as "halt -r"

Offline

#25 2008-09-05 05:34:27

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: Shutdown and Reboot without going root

dsr wrote:

Their command-line options differ, so you probably want to read the manpages, but I believe during normal operation (runlevel 3 or 5) the following is correct:

"shutdown -h now" is functionally the same as "poweroff" which is functionally the same as "halt -p" or just "halt"
"shutdown -r now" is functionally the same as "reboot" which is functionally the same as "halt -r"

Thanks. On my system though, "poweroff" is quite fast (seems to just kill the X server, then I see all the background processes being terminated in the console, then it powers off) whereas "shutdown -h now" takes a minute and doesn't seem to be doing anything. I was mostly curious to know if it's doing during that minute that "poweroff" doesn't do and if that matters.

Maybe it's more for multiuser systems to give others time to save their work etc (since replacing "now" with an integer delays the shutdown and sends the message to others).


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

Board footer

Powered by FluxBB