大网数据广告活动
服务器运维问答

systemd start as unprivileged user in a group

· 52CE 我爱测

I'd like users in group foogroup to be able to: systemctl start foo.service , systemctl stop foo.service , systemctl status foo.service , and journalctl -u foo.service without using elevated privileges. Is that possible? I have a…

问题原文

原帖链接 · Stewart · CC BY-SA 4.0

I'd like users in group foogroup to be able to:

  • systemctl start foo.service,
  • systemctl stop foo.service,
  • systemctl status foo.service, and
  • journalctl -u foo.service

without using elevated privileges. Is that possible?


I have a systemd service which looks like:

[Unit]
Description=foo service

[Service]
Type=simple
ExecStart=/bin/sleep infinity
User=foobot
Group=foogroup

Where foobot is a system user.

I know we can install the unit file to ~/.config/systemd/user/ to allow an unprivileged user to use systemd, but this doesn't really help a group.

Note: I plan on using cockpit so adding systemctl to /etc/sudoers isn't going to help.

已采纳解答

原帖链接 · Stewart · CC BY-SA 4.0

I would have accepted Tollef Fog Heen's answer if I wasn't on a Debian distribution, however because debian uses polkit (<0.106), *.rules are not available. The equivalent file in Debian is:

/etc/polkit-1/localauthority/50-local.d/manage-units.pkla
----
[Allow users to manage services]
Identity=unix-group:somegroup
Action=org.freedesktop.systemd1.manage-units
ResultActive=yes

However, be warned that this is not exactly equivalent. It allows a group to manage services, but doesn't specify which services the group is allowed to manage. Also, it doesn't limit which 'verb' is permitted. However I have noticed that while systemd start is permitted, things like systemd enable are still unavailable which is protected by file permissions.

I have another open question on SO regarding the differences between the capabilities of the *.rules and the *.pkla files of this answer here.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-03-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。