# Running Node-RED as a service, under a different user, on boot, on a server

**URL:** <https://discourse.nodered.org/t/running-node-red-as-a-service-under-a-different-user-on-boot-on-a-server/57625>\
**Category:** General\
**Created:** [2 February 2022 08:35 UTC](https://discourse.nodered.org/t/running-node-red-as-a-service-under-a-different-user-on-boot-on-a-server/57625 "2022-02-02T08:35:34Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![kitwar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kitwar/32/55008_2.png) [@kitwar](https://discourse.nodered.org/u/kitwar)\
**Post date:** [2 February 2022 08:35 UTC](https://discourse.nodered.org/t/running-node-red-as-a-service-under-a-different-user-on-boot-on-a-server/57625/1 "2022-02-02T08:35:34Z")

</div>

Hello! For a very long time I kept having random hardfreezing, sometimes while I sleep, sometimes while I'm working, sometimes at login, sometimes it's up for days. I used different linux distros, debian and arch, I replaced every part of the computer until now I am down to one and the cause is clear. It's a broken old video card and XSERVER crashes.

Someone told me I could run Node-RED under a different user, on boot, so if my user session crashes, Node-RED would keep working.

What do you think about this? I am a bit overwhelmed by stress those days and there are clients counting on my service.

Can I be guided into doing this right?

---

<div class="post-metadata">

**Author:** ![kitwar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kitwar/32/55008_2.png) [@kitwar](https://discourse.nodered.org/u/kitwar)\
**Post date:** [2 February 2022 08:39 UTC](https://discourse.nodered.org/t/running-node-red-as-a-service-under-a-different-user-on-boot-on-a-server/57625/2 "2022-02-02T08:39:39Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/9/a9a8d06fe2ec7d270844116bb91c2fb0333a47af.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [2 February 2022 09:13 UTC](https://discourse.nodered.org/t/running-node-red-as-a-service-under-a-different-user-on-boot-on-a-server/57625/3 "2022-02-02T09:13:15Z")

</div>

If you are using a Debian based OS such as Ubuntu then the [recommended Debian/Ubuntu/Pi install script](https://nodered.org/docs/getting-started/raspberrypi) installs systemd scripts for running at boot. You don't need to run it as a different user, just not running in the xserver session.

---

<div class="post-metadata">

**Author:** ![kitwar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kitwar/32/55008_2.png) [@kitwar](https://discourse.nodered.org/u/kitwar)\
**Post date:** [2 February 2022 09:16 UTC](https://discourse.nodered.org/t/running-node-red-as-a-service-under-a-different-user-on-boot-on-a-server/57625/4 "2022-02-02T09:16:12Z")

</div>

It's an arch based system, unfortunately.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [2 February 2022 09:37 UTC](https://discourse.nodered.org/t/running-node-red-as-a-service-under-a-different-user-on-boot-on-a-server/57625/5 "2022-02-02T09:37:36Z")

</div>

In that case you will need to look up how to run things from root in Arch.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [2 February 2022 15:27 UTC](https://discourse.nodered.org/t/running-node-red-as-a-service-under-a-different-user-on-boot-on-a-server/57625/6 "2022-02-02T15:27:11Z")

</div>

> [@Colin](#):
>
> from root in Arch

Depending on what you are using this server and node-red for, if you need reasonable security, you should **most certainly NOT run Node-RED as root**. Doing so is not only less secure but is likely to cause other operational issues.

Instead, create a user and group specifically for running Node-RED and adjust the startup script to use that user. Also make sure that the userDir folder is owned by the node-red user/group. Obviously, you need to make sure that the node-red user and/or group has access to whatever resources you want accessible from Node-RED (e.g. serial port, etc). You can then also make sure that the node-red user has no login rights so that the account can't be misused that way.

---

<div class="post-metadata">

**Author:** ![kitwar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kitwar/32/55008_2.png) [@kitwar](https://discourse.nodered.org/u/kitwar)\
**Post date:** [2 February 2022 19:26 UTC](https://discourse.nodered.org/t/running-node-red-as-a-service-under-a-different-user-on-boot-on-a-server/57625/7 "2022-02-02T19:26:19Z")

</div>

I succeeded running it as a service in the following way:

_(NAME and USER are replaced with correct values)_

```auto
[Unit]
Description=NAME
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=USER
ExecStart=/home/USER/.node-red/NAME.sh
WorkingDirectory=/home/USER/.node-red

[Install]
WantedBy=multi-user.target

```

I was getting `Error: ENOENT: no such file or directory` errors but I fixed it by running my script from inside the **~/.node-red** folder, which I didn't at first.

I don't think "WorkingDirectory" matters but I was trying to fix the error which didn't work by adding it.

@TotallyInformation Thank you for the detailed information, that is what I was recommended to do, you also added some more things to be careful about. Right now I tried doing what @Colin said and just run it as a service, I'll see at the next hard freeze (xserver crash) if node-red keeps working and post an update.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [2 February 2022 19:43 UTC](https://discourse.nodered.org/t/running-node-red-as-a-service-under-a-different-user-on-boot-on-a-server/57625/8 "2022-02-02T19:43:08Z")

</div>

If you look in my GitHub, you will find a repo called alternate installer which has a complete systemd service definition example script. That has some possibly nice extras such as environment variables from a file and some sensible service dependencies.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [2 February 2022 20:18 UTC](https://discourse.nodered.org/t/running-node-red-as-a-service-under-a-different-user-on-boot-on-a-server/57625/9 "2022-02-02T20:18:18Z")

</div>

> [@TotallyInformation](#):
>
> > [@Colin](#):
> >
> > from root in Arch
> 
> Depending on what you are using this server and node-red for, if you need reasonable security, you should **most certainly NOT run Node-RED as root**.

That was google helpfully interpreting my input on my phone. I meant boot of course, which is what the question is about. Definitely don't run node-red as root.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 April 2022 20:18 UTC](https://discourse.nodered.org/t/running-node-red-as-a-service-under-a-different-user-on-boot-on-a-server/57625/10 "2022-04-03T20:18:52Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
