How do I create a service on CentOS running as a different user than root?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
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
[Unit]
Description=mydir nodejs server
[Service]
ExecStart=/home/rails/mydir/start.sh
ExecStop=/home/rails/mydir/stop.sh
[Install]
WantedBy=multi-user.target
What else do I need to do to get the service to run as the user I want?
centos systemd root startup services
add a comment |Â
up vote
0
down vote
favorite
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
[Unit]
Description=mydir nodejs server
[Service]
ExecStart=/home/rails/mydir/start.sh
ExecStop=/home/rails/mydir/stop.sh
[Install]
WantedBy=multi-user.target
What else do I need to do to get the service to run as the user I want?
centos systemd root startup services
It looks like a quick Google would produce some useful examples, including some right here on U&LSE.
â John Bollinger
May 7 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 at 20:44
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
[Unit]
Description=mydir nodejs server
[Service]
ExecStart=/home/rails/mydir/start.sh
ExecStop=/home/rails/mydir/stop.sh
[Install]
WantedBy=multi-user.target
What else do I need to do to get the service to run as the user I want?
centos systemd root startup services
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
[Unit]
Description=mydir nodejs server
[Service]
ExecStart=/home/rails/mydir/start.sh
ExecStop=/home/rails/mydir/stop.sh
[Install]
WantedBy=multi-user.target
What else do I need to do to get the service to run as the user I want?
centos systemd root startup services
edited May 8 at 14:50
cherdt
6341414
6341414
asked May 7 at 19:57
Dave
363827
363827
It looks like a quick Google would produce some useful examples, including some right here on U&LSE.
â John Bollinger
May 7 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 at 20:44
add a comment |Â
It looks like a quick Google would produce some useful examples, including some right here on U&LSE.
â John Bollinger
May 7 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 at 20:44
It looks like a quick Google would produce some useful examples, including some right here on U&LSE.
â John Bollinger
May 7 at 20:05
It looks like a quick Google would produce some useful examples, including some right here on U&LSE.
â John Bollinger
May 7 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 at 20:44
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 at 20:44
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You can specify the user and group under the [Service]
heading:
User=rails
Group=rails
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
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You can specify the user and group under the [Service]
heading:
User=rails
Group=rails
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
add a comment |Â
up vote
0
down vote
accepted
You can specify the user and group under the [Service]
heading:
User=rails
Group=rails
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
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You can specify the user and group under the [Service]
heading:
User=rails
Group=rails
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 can specify the user and group under the [Service]
heading:
User=rails
Group=rails
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
answered May 8 at 14:28
cherdt
6341414
6341414
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442394%2fhow-do-i-create-a-service-on-centos-running-as-a-different-user-than-root%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
It looks like a quick Google would produce some useful examples, including some right here on U&LSE.
â John Bollinger
May 7 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 at 20:44