I have a service in the form of a node.js application set up with Systemd on Raspbian Jessie and it is using its own user account. However, I am finding that the service does not run correctly because it does not have the necessary permissions. One of the node modules I installed requires root access. If I run the application manually with sudo everything works fine.
Is there a way to tell systemd to run the service with sudo?
sudo
has nothing to with it.Typically you instruct systemd to run a service as a specific user/group with a
User=
andGroup=
directive in the[Service]
section of the unit file.Set those to root (or remove them, as running as root is the default).
To clear,
systemd
system services run as root by default, but there is still a difference between the default behavior and running a system service withUser=root
.As documented in Environment variables in spawned processes, these variables are only set if
User=
is set:I tested to confirm this finding. So if you want to run a systemd service as root that needs one of the above variables, you need to set
User=root
.a temporary solution, but got it to work in a pinch:
Can run with a user who has sudo privileges in a systemd unit file like so:
Run it as a system user in this case by default the service is running as root.