How to run service not as root

5,982

Use:

User=myuser

In your unit file.

This is documented in man systemd.exec

Also, custom files should not go in /usr/lib/systemd/system, they should go in /etc/systemd/system. The former is where packages install their files. The later is where system administrators should put their files.

Share:
5,982

Related videos on Youtube

Wernfried Domscheit
Author by

Wernfried Domscheit

Updated on September 18, 2022

Comments

  • Wernfried Domscheit
    Wernfried Domscheit over 1 year

    I created successfully a service on my Linux RedHat by copy the Unit-File to /usr/lib/systemd/system/mediation.service

    I can successfully start/stop/enable/... the service with

    systemctl enable mediation
    systemctl start mediation
    etc.
    

    However, since systemctl is usually executed by root, my application runs also as root. How can I configure the service that it runs under a different (non-privileged) user?

    • ivanempire
      ivanempire almost 8 years
      What if you separately add the commands to the sudoers file of the non-root user you want to run as?