I’v wrote a very small script that stream my favorite radio station the whole time the computer runs to avoid one minutes of advertisement on every reconnection to the server of the radio station.
This script runs as systemd service which is fairly stable, but if there is an interruption of the internet of the streaming server, I have either to restart the computer or to restart the service with root rights. So I was searching for a solution that gives me the possibility to control this service as unprivileged user (explicit no su, sudo or whatever).
I found something in Google, but nothing is working:
You can restart a system-wide systemd service as a non-root user at any time by configuring sudoers via visudo to allow that specific user to runsystemctl restart.
Setting Up Permitted Access
Open the sudo configuration file safely by running:
bash
sudo visudo
Verwende Code mit Vorsicht.
Add a rule granting the specific user rights to restart your exact service without typing a password (or requiring their own password):
Replace username with your actual Linux user and myservicename.service with your target service name.
Restarting the Service Anytime
Once configured, the user can run this command from their own session at any moment:
bash
sudo systemctl restart myservicename.service
This is my /etc/sudoers:
## User privilege specification
root ALL=(ALL:ALL) ALL
hk ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart vlc-Server.service
Is there a possibility to get this to work, or would be the suid-bit an option, I tried this on my script without success. I had never success with this suid-bit, it never worked even I’ve studied the usage of it.
Is there any specific reason why the streaming script runs as root? If you can run it as user, you could set up a systemd script to start it at login, and restart it with the following command:
systemctl --user restart myservicename
systemd user services/timers etc are stored in ~/.config/systemd/user/, and are enabled/disabled etc in the same way as system services. You just need to add --user to the command and omit the sudo.
Edit 2026-08-30T11:45:00Z:
You might find it easier to add a dropin file to the /etc/sudoers.d/ directory rather than modify the /etc/sudoers file. This command should do it:
Thank you for your answer. User service is not possible for what reason ever, when I start the script (not as service I get a suspicious error message:
Temporary file /usr/bin/sediU623N cannot be opened: No permission
I’ve tried you suggestion to create a file in /etc/sudoers.d/ (with your command), but I will be still prompted to enter my password when I invoke systemctl restart vlc-Server.service.
Here the content of /etc/sudoers.d/restart-vlc-Server-without-sudo:
[linux hk]# cat /etc/sudoers.d/restart-vlc-Server-without-sudo
hk ALL=(ALL) NOPASSWD: /bin/systemctl restart vlc-Server.service
Or is it impossible because its as script and not a binary executable. I’ve just found this here in regard to SUID-Bit: SUID doesn’t work with scripts
So I assume that I have more or less the same problem.
Mod edit:Consecutive posts merged.
If there are no intervening replies, please edit your previous post instead to add updates; add @mentions where needed. Cheers!
Nothing should ever write to /usr except for the package manager, and it is certainly not the proper place to store temporary files. Temporary files should go under /tmp.
This is wrong. Spaces on that line are interpreted as separators for the multiple commands you are allowed to execute. Therefore, that whole command should be enclosed in quotes.