Reboot linux without root

Содержание
  1. выключить комп через терминал(shutdown) без sudo. как ?
  2. Если systemd, то всё просто
  3. unixforum.org
  4. Выключение и перезагрузка от обычного юзера (Slackware 12.1)
  5. Выключение и перезагрузка от обычного юзера
  6. Re: Выключение и перезагрузка от обычного юзера
  7. Re: Выключение и перезагрузка от обычного юзера
  8. Re: Выключение и перезагрузка от обычного юзера
  9. Re: Выключение и перезагрузка от обычного юзера
  10. Re: Выключение и перезагрузка от обычного юзера
  11. Re: Выключение и перезагрузка от обычного юзера
  12. Re: Выключение и перезагрузка от обычного юзера
  13. Re: Выключение и перезагрузка от обычного юзера
  14. Re: Выключение и перезагрузка от обычного юзера
  15. Re: Выключение и перезагрузка от обычного юзера
  16. Re: Выключение и перезагрузка от обычного юзера
  17. Arch Linux
  18. #1 2008-09-04 00:19:17
  19. Shutdown and Reboot without going root
  20. #2 2008-09-04 01:18:56
  21. Re: Shutdown and Reboot without going root
  22. #3 2008-09-04 03:04:36
  23. Re: Shutdown and Reboot without going root
  24. #4 2008-09-04 03:33:07
  25. Re: Shutdown and Reboot without going root
  26. #5 2008-09-04 05:25:43
  27. Re: Shutdown and Reboot without going root
  28. #6 2008-09-04 05:34:42
  29. Re: Shutdown and Reboot without going root
  30. #7 2008-09-04 08:45:22
  31. Re: Shutdown and Reboot without going root
  32. #8 2008-09-04 11:58:32
  33. Re: Shutdown and Reboot without going root
  34. #9 2008-09-04 12:18:08
  35. Re: Shutdown and Reboot without going root
  36. #10 2008-09-04 18:07:14
  37. Re: Shutdown and Reboot without going root
  38. #11 2008-09-04 18:22:48
  39. Re: Shutdown and Reboot without going root
  40. #12 2008-09-04 18:24:18
  41. Re: Shutdown and Reboot without going root
  42. #13 2008-09-04 18:24:51
  43. Re: Shutdown and Reboot without going root
  44. #14 2008-09-04 19:37:18
  45. Re: Shutdown and Reboot without going root
  46. #15 2008-09-04 20:01:49
  47. Re: Shutdown and Reboot without going root
  48. #16 2008-09-04 20:29:04
  49. Re: Shutdown and Reboot without going root
  50. #17 2008-09-04 21:21:36
  51. Re: Shutdown and Reboot without going root
  52. #18 2008-09-04 21:29:30
  53. Re: Shutdown and Reboot without going root
  54. #19 2008-09-04 22:42:59
  55. Re: Shutdown and Reboot without going root
  56. #20 2008-09-04 23:06:58
  57. Re: Shutdown and Reboot without going root
  58. #21 2008-09-04 23:09:46
  59. Re: Shutdown and Reboot without going root
  60. #22 2008-09-04 23:48:58
  61. Re: Shutdown and Reboot without going root
  62. #23 2008-09-05 00:01:31
  63. Re: Shutdown and Reboot without going root
  64. #24 2008-09-05 00:42:05
  65. Re: Shutdown and Reboot without going root
  66. #25 2008-09-05 05:34:27
  67. Re: Shutdown and Reboot without going root

выключить комп через терминал(shutdown) без sudo. как ?

приветствую. пишу для себя программку для выключения/перезагрузки системы по таймеру(аналог EasyShutdown под linux), ребутить систему решил через библиотеку subprocess(python) которая запускает скрипты bash в python’e, но не знаю как сделать, что бы можно было перезагрузить машину без su/sudo.

Можно через dbus и ConsoleKit

Проще через судов, а если серьёзно то добавить пользователя в группу, не помню какую так как нет возможности проверить

этот вариант не катит, надо что бы программа запускалась «с коробки» на разных машинах, а не только у меня.

спасибо, буду пробовать, хотя не до конца понимаю что это за кусок кода.

зафига тебе выключать чужие машины

нее, ты не так понял 🙂 просто что бы программка работала на разных компьютерах(под разными учетными записями), а не только у меня(потому-что я прописал права доступа)

ConsoleKit — это такой демон, обслуживащий пользовательские сессии. Им можно управлять через dbus. Только вот его вроде выпиливают сейчас повсюду. Если у тебя systemd, то фокус не прокатит. Может заглянут знатоки и подскажут, как это сделать через logind.

А пароль кто будет вводить?

которая запускает скрипты bash в python’e

может сразу на баше написать?

да, прочитал о ConsoleKit так там в разных версиях может по разному себя вести, bash не катит, т.к. это будет аплет для unity с менюшками на Gtk, даже не знаю как быть, хотелось бы универсальность программки, что бы под разными версиями запускался системы/пакетов.

Вроде бы с правами надо разбираться через polkit.

:NOPASSWD — настраивается в /etc/sudoers.

Стрёмно как-то давать беспарольный sudo даже на одну команду. Хотя может это паранойя. Но всё равно ТСу это не подходит.

если ты делаешь утилиту для других людей, утилиту (работающую «из коробки») для которой нужны повышенные привелегии, такие как «вылючение компьютера» или «стереть все файлы из /home/» (шутка) — то просто укажи в документации к утилите это требование.

. мол — «запускайте от root или через sudo».

второй вариант: раздели свою утилиту на две слабосвязанные части. одна часть это сервисный-юнит (запускаемый через systemd и висящий в системе постоянно), а вторая часть это клиентская часть. клиентская часть — будет связываться со своей серверной частью через dBus, например.

кстати, во втором варианте — я разумеется вижу угрозу безопасности (так как кроме именно твоей программы — связаться с серверной частью сможет также и программа злоумышленника, которая не имеет повышенных полномочий).

спасибо, буду пробовать, хотя не до конца понимаю что это за кусок кода.

Тогда уж не вызывать bash из python только для того, чтобы дернуть dbus-send, а использовать dbus-python.

Если systemd, то всё просто

poweroff или systemctl poweroff . По дефолту разрешения таковы, что единственный активный пользователь сможет вырубить машину без получения прав суперпользователя.

В случае с systemd такой демон уже написали и называется он logind 🙂

Источник

unixforum.org

Форум для пользователей UNIX-подобных систем

  • Темы без ответов
  • Активные темы
  • Поиск
  • Статус форума
Читайте также:  Arch linux in kvm

Выключение и перезагрузка от обычного юзера (Slackware 12.1)

Модератор: Bizdelnick

Выключение и перезагрузка от обычного юзера

Сообщение sidd » 11.09.2008 23:46

$ /sbin/shutdown
shutdown: you must be root to do that!
sidd@home:

$ /sbin/reboot
reboot: must be superuser.

Re: Выключение и перезагрузка от обычного юзера

Сообщение devilr » 12.09.2008 00:14

Re: Выключение и перезагрузка от обычного юзера

Сообщение Mydvane » 12.09.2008 00:40

$ /sbin/shutdown
shutdown: you must be root to do that!
sidd@home:

$ /sbin/reboot
reboot: must be superuser.

sudo рулит

Re: Выключение и перезагрузка от обычного юзера

Сообщение sidd » 15.09.2008 18:51

Re: Выключение и перезагрузка от обычного юзера

Сообщение Flaming » 15.09.2008 18:59

Re: Выключение и перезагрузка от обычного юзера

Сообщение sidd » 18.09.2008 18:18

Re: Выключение и перезагрузка от обычного юзера

Сообщение devilr » 18.09.2008 20:25

Re: Выключение и перезагрузка от обычного юзера

Сообщение Flaming » 18.09.2008 21:29

Re: Выключение и перезагрузка от обычного юзера

Сообщение t.t » 18.09.2008 21:35

Re: Выключение и перезагрузка от обычного юзера

Сообщение devilr » 18.09.2008 21:36

Re: Выключение и перезагрузка от обычного юзера

Сообщение t.t » 18.09.2008 22:03

Того, кому надо только «перезагружать комп», добавлять в группу wheel — это даже не потенциальная дыра (как с битом suid), это уже реальная дырища.

Re: Выключение и перезагрузка от обычного юзера

Сообщение devilr » 18.09.2008 23:36

Источник

Arch Linux

You are not logged in.

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

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)

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

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)

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

Re: Shutdown and Reboot without going root

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

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

Re: Shutdown and Reboot without going root

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

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

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

Re: Shutdown and Reboot without going root

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

Microshaft delenda est

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

Re: Shutdown and Reboot without going root

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:

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

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

Reboot

I use fluxbox and this works for me.

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

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

Re: Shutdown and Reboot without going root

How about this wiki-entry?
=> Allow_users_to_shutdown

«The mind can make a heaven out of hell or a hell out of heaven» — John Milton

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

Re: Shutdown and Reboot without going root

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.

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

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 !?

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.

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

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 !?

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.

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

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 !?

Читайте также:  После установки kali linux не могу войти

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 ?

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.

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

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 !?

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)

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

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

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

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 !?

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.

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

Re: Shutdown and Reboot without going root

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

I created off an on in /usr/sbin.

off shuts me down and on reboots. Simple eh?

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

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 !?

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.

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

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)?

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

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.

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

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.

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

Читайте также:  Как дефрагментировать диск mac os

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.

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

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.

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.

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

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)

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

Re: Shutdown and Reboot without going root

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

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

Re: Shutdown and Reboot without going root

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)

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

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)?

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»

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

Re: Shutdown and Reboot without going root

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).

Источник

Оцените статью