The Linux Page

Prevent shutdown from GUI while using ssh from another computer

Polkit-1

This feature works along systemd and loginctl to create sessions for users and check current statuses defined in rules files. This is supposed to be enough to prevent someone from shuting down a computer from the GUI when an administrator is logged in via SSH.

Thus far, I have not been able to find a way to get that to work for like 1 year. I'm going to put information about my research. Various pages talking about, documentation, etc.

First of all, there is a manual page which is likely already installed on your system:

man pklocalauthority

Now a list of pages I have found that help me try to understand what could be wrong on my installs:

https://askubuntu.com/questions/1190/how-can-i-make-shutdown-not-require-admin-password

Molly Gard

*** This does not seem to work anymore ***

I now have 4 servers at home, 2 of which I'm in full control, but 2 that my kids use too. So once in a while I end up working with those servers too and I want to prevent them from being shutdown on me. It looks like just being logged in with ssh already prevents the shutdown, but I wanted to make sure by using additional safeguards.

One way is to use molly-guard, my idea is to prevent the inadvertend shutdown when I'm on the computer, not to remove the capability of shutting down the computer from X-Windows (the GUI shutdown is fine when I'm not using the computers.)

The following installs the molly-guard package:

sudo apt-get install molly-guard

If you want to completely prevent the shutdown, you can also add a file. Edit with vim like this:

sudo vim /etc/molly-guard/run.d/99-prevent-all

and then put the following in the file:

#!/bin/sh
exit 1

Finally, make sure that new file is executable otherwise it will likely be ignored:

sudo chmod 755 /etc/molly-guard/run.d/99-prevent-all

Now you cannot shutdown until you edit that new prevent all file and do something like the following:

#!/bin/sh
#exit 1

(i.e. comment out the exit 1 command so the default apply which is exit 0 and it will now accept shutdown commands.)

Source: http://askubuntu.com/questions/93542/how-to-disable-shutdown-reboot-suspend-hibernate