I'm using CentOS 7. I want to run a nodeJS script as a service but run the service as the "rails" user. As root, I created the file /usr/lib/systemd/system/myservice.service, with the contents

Description=mydir nodejs server



What else do I need to do to get the service to run as the user I want?

  • It looks like a quick Google would produce some useful examples, including some right here on U&LSE. May 7, 2018 at 20:05
  • Yeah but those are dealing with older versions of CentOS than what I listed in my question. E.g. top Google result is centos.org/forums/viewtopic.php?t=54865 but that deals with CenteOS 5.
    – Dave
    May 7, 2018 at 20:44

1 Answer 1


You can specify the user and group under the [Service] heading:


See the credentials section of systemd.exec for details.

Also, use /etc/systemd/system/myservice.service as the path for service files created by the system administrator instead of /usr/lib/systemd/system. See Creating and Modifying systemd Unit Files

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .