Разрешить "остановку systemctl" для всех пользователей? (systemd + debian)

1236
David Stark

Можно ли разрешить "systemctl halt" для всех пользователей?

На данный момент только команды:

systemctl poweroff & systemctl reboot work on my system (Debian Jessie) 

Когда я вызываю systemctl halt как обычный пользователь, я получаю следующее сообщение:

Failed to start halt.target: Access denied 

Я попробовал следующие методы:

  1. Метод - я попытался добавить новое действие в: /usr/share/polkit-1/actions/org.freedesktop.login1.policy

Я скопировал действие

<action id="org.freedesktop.login1.power-off"> to <action id="org.freedesktop.login1.halt"> 
  1. Метод (и который работал) был для chmod u + s / sbin / halt, но поскольку / sbin / halt является ссылкой на -> / bin / systemctl, это, вероятно, не очень хорошая идея
0
Обратите внимание, что `halt` и` systemctl halt` - две разные команды. Даже если одна символическая ссылка на другую, они все равно ведут себя по-разному. grawity 7 лет назад 0

1 ответ на вопрос

2
grawity

Step 1: Wait several months until Debian Stretch is released – you need at least systemd v227, with commits 2ac3930f (polkit checking for /sbin/halt) and 88ced61b (extended polkit data for systemctl halt etc.)

Step 2: Create a polkit rule in… Actually, no, that won't be enough because even Stretch still has polkit v0.105, which did not support the JS-based rules yet; only the considerably more limited .pkla format. That said, v0.113 is finally in "experimental".

But if you happen to upgrade to systemd ≥v227 and polkit ≥v0.113, a rule such as this should work:

/* copy to /etc/polkit-1/rules.d/systemd-allow-halt.rules */ polkit.addRule(function(action, subject) { if (action.id == "org.freedesktop.systemd1.manage-units" && action.lookup("unit") == "halt.service") { return polkit.Result.YES; } }); 

So, teach yourself to type systemctl poweroff instead. "Halt" isn't the normal shutdown command; it's the command to literally halt the machine – without powering it off. It's not very useful.

If you do find it useful, use sudo instead:

# /etc/sudoers ALL ALL=(root) NOPASSWD: /usr/bin/systemctl halt, /sbin/halt 

Похожие вопросы