You are not logged in.

#1 2020-12-12 03:32:13

vordoo
Member
Registered: 2013-03-24
Posts: 30

[solved] Forbid poweroffs and reboots when another user is logged-in?

Hi,

Options for forbidding poweroffs and reboots when another user is logged-in highly appreciated. Say, when each user is working on his own tty locally (probably not simultaneously) or over ssh, remote-desktop, etc.

Thanks!

Last edited by vordoo (2020-12-14 12:00:08)

Offline

#2 2020-12-12 04:32:34

twobooks
Member
From: rainforest
Registered: 2020-06-23
Posts: 46

Re: [solved] Forbid poweroffs and reboots when another user is logged-in?

poweroff [OPTIONS...]

Power off the system.

Options:
     --help      Show this help
     --halt      Halt the machine
  -p --poweroff  Switch off the machine
     --reboot    Reboot the machine
  -f --force     Force immediate halt/power-off/reboot
  -w --wtmp-only Don't halt/power-off/reboot, just write wtmp record
  -d --no-wtmp   Don't write wtmp record
     --no-wall   Don't send wall message before halt/power-off/reboot

See the halt(8) man page for details.

it seems no option by poweroff command.
I think you can write your own script to achieve it.

Offline

#3 2020-12-12 16:54:58

twelveeighty
Member
From: Alberta, Canada
Registered: 2011-09-04
Posts: 1,158

Re: [solved] Forbid poweroffs and reboots when another user is logged-in?

vordoo wrote:

... forbidding poweroffs and reboots

Forbidding and preventing are two very different things. You can use regular sudo/polkit configuration to *forbid* regular users from powering off and rebooting the machine.

However, if you want users to remain to be able to poweroff, then you need a warning system to *prevent* shutting down the machine when others are logged in. For example, you can wrap poweroff in a script that first checks for existing sessions and bails if it finds any.

If you want, you can combine both and use sudo/polkit to only grant access to the wrapper script for less privileged users.

Offline

#4 2020-12-13 19:12:27

vordoo
Member
Registered: 2013-03-24
Posts: 30

Re: [solved] Forbid poweroffs and reboots when another user is logged-in?

However, if you want users to remain to be able to poweroff, then you need a warning system to *prevent* shutting down the machine when others are logged in. For example, you can wrap poweroff in a script that first checks for existing sessions and bails if it finds any.

Looking for an elegant-way/options of doing what you said, but not necessarily with a user warning: *Forbidding* (make impossible à la Webster Dictionary) poweroffs and reboots when another user is logged-in ;-)

With the wrapping option you must make sure all options are wraped: shutdown, poweroff, restart, reboot, whatever... Looking for a more generic option, if any.

Thanks!

Offline

#5 2020-12-13 19:35:28

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 8,486
Website

Re: [solved] Forbid poweroffs and reboots when another user is logged-in?

https://bbs.archlinux.org/viewtopic.php?id=198904 (but only add the org.freedesktop.login1.power-off-multiple-sessions & org.freedesktop.login1.reboot-multiple-sessions action IDs.)


Para todos todo, para nosotros nada

Offline

#6 2020-12-14 11:55:43

vordoo
Member
Registered: 2013-03-24
Posts: 30

Re: [solved] Forbid poweroffs and reboots when another user is logged-in?

Head_on_a_Stick wrote:

https://bbs.archlinux.org/viewtopic.php?id=198904 (but only add the org.freedesktop.login1.power-off-multiple-sessions & org.freedesktop.login1.reboot-multiple-sessions action IDs.)

Thanks, you nailed it. For prosperity I'll add this link too (prevent non-root users from issuing shutdowns or reboots):
https://superuser.com/questions/354678/ … ns-or-rebo.

Last edited by vordoo (2020-12-14 11:57:55)

Offline

Board footer

Powered by FluxBB