Allow `dietpi` user to remotely stop and start services

I have added a service via dietpi-services that I would like to be able to control via SSH e.g.

ssh dietpi@remote-machine 'dietpi-services stop myservice'

This works when issued with root credentials but obviously, that is not the answer. Is there a ‘best’ way to do this?

As of now, I have tried adding:

%dietpi ALL= NOPASSWD: /boot/dietpi/dietpi-services stop myservice

…to /etc/sudoers, but no luck:

[FAILED] DietPi-Services | Root privileges required. Please run the command with “sudo” or “G_SUDO”.

The reason that I use DietPi so much is that I am not massively familiar with Linux and so don’t know whether I am even going down the wrong rabbit-hole!

If you added a service with dietpi-services then it got added to /etc/systemd/system which will always be controlled by user root, I think you will always need sudo to run it.
However, you can run it as a regular user by adding usr and group to the service file.
There is a discussion here https://askubuntu.com/questions/1371102/running-systemd-service-as-user-rather-than-root

I have not tested this, please report back if it works as you want it.

The other option is to create a user service and run that, see above link.

Yes sudo would need to be added to the command.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.