Skip to main content
2 of 5
improved formatting
Thomas
  • 6.6k
  • 8
  • 31
  • 34

Restarting systemd service only as a specific user?

I created some systemd services which basically works:

location:

/etc/systemd/system/multi-user.target.wants/publicapi.service

content:

[Unit]
Description=public api startup script

[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=-/etc/environment
WorkingDirectory=/home/techops
ExecStart=/home/techops/publicapi start
ExecStop=/home/techops/publicapi stop

[Install]
WantedBy=multi-user.target

When I try to restart the service as techops user in the command line, I get the following output:

==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to start 'publicapi.service'.
Multiple identities can be used for authentication:
 1.  Myself,,, (defaultuser)
 2.  ,,, (techops)
Choose identity to authenticate as (1-2):

I want that only techops can restart services and I want that this prompt does not appear when being logged in as techops. How can I do that?

I read that there are different approaches with polkit-1 or sudoers, but I'm unsure what I exactly want to do here.

Bevor
  • 691
  • 2
  • 11
  • 22