# Node-red : file -- write & set ownership

**URL:** https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398
**Category:** General
**Created:** [27 October 2023 14:32 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398 "2023-10-27T14:32:03Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)
#### Post date: [27 October 2023 14:32 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/1 "2023-10-27T14:32:03Z")

</div>

It's about "node-red : file -- write", how to set the ownership of the file to be written?  
Is it always set to 'root:root'? If yes, how to change it within NR?  
It's on RaspberryPI with Raspbian GNU/Linux 11 (bullseye).

---

<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: [27 October 2023 14:54 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/2 "2023-10-27T14:54:06Z")

</div>

It should be the user/group that is running node-red, not root:root. Unless you are running node-red as root which is generally not good.  
I don't know how to change that other then using `sudo chown` in an exec node and setting sudo up to allow that command to be used without a password.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [27 October 2023 15:07 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/3 "2023-10-27T15:07:58Z")

</div>

What directory are you creating the file in, and what are the ownership and permissions for the directory? `ls -ld /full/path/to/directory`

---

<div class="post-metadata">

### Author: ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)
#### Post date: [27 October 2023 15:08 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/4 "2023-10-27T15:08:53Z")

</div>

@Colin Yes, looks like my NR installation should not be "running node-red as root". Will have to change the installation I guess.

---

<div class="post-metadata">

### Author: ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)
#### Post date: [27 October 2023 15:15 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/5 "2023-10-27T15:15:33Z")

</div>

@jbudd

```auto
$ ls -ld ~/.red2000/uibuilder/xRED1/data
drwxr-xr-x 2 pi pi 4096 Oct 27 16:13 /home/pi/.red2000/uibuilder/xRED1/data

$ ls -lt *.ini
-rw-r--r-- 1 root root 1306 Oct 27 17:01 XW.ini

```

As you see this is a 'uibuilder' project. Maybe that is part of the situation?

---

<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: [27 October 2023 15:16 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/6 "2023-10-27T15:16:52Z")

</div>

How are you running node-red? If you are using a systemd script then the user and group can be set in there.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [27 October 2023 15:22 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/7 "2023-10-27T15:22:42Z")

</div>

> [@gNeandr](#):
>
> As you see this is a 'uibuilder' project. Maybe that is part of the situation?

I don't think so.  
As far as I know all files and directories created below /home/pi should belong to pi.

Your problem is surely caused by running Node-red as root but in /home/pi/.red2000  
So when the file is created it is owned by (and has the default permissions for) root  
I suspect that merely changing the username in the systemd script won't fix it, you probably have to do a recursive chown on the directory, changing user and group.  
Or safer, delete and reinstall Node-red.

---

<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: [27 October 2023 15:39 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/8 "2023-10-27T15:39:33Z")

</div>

> [@jbudd](#):
>
> Or safer, delete and reinstall Node-red.

That won't change the ownership of existing files in the user folder.

---

<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: [27 October 2023 16:02 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/9 "2023-10-27T16:02:04Z")

</div>

> [@gNeandr](#):
>
> As you see this is a 'uibuilder' project. Maybe that is part of the situation?

No!

UIBUILDER folders must be readable by Node-RED (and writable preferably, you will loose some features if not). But there are no other filing system requirements.

The issue is absolutely caused by running under root. Since any folder or file created or amended by Node-RED will end up being owned by root/root. This is a _BAD_ thing for various reasons.

There is another thread talking about how to run Node-RED with different user/group properties so you can see how to fix it there. But you will also need to change the ownership of all of the Node-RED folders and files back to pi/pi.

---

<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: [27 October 2023 16:14 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/10 "2023-10-27T16:14:57Z")

</div>

This is cropping up repeatedly with seemingly a new generation of Node-RED users. So I've created an FAQ:

> [@Should I install and/or run Node-RED with an admin account? (SUDO)](https://discourse.nodered.org/t/should-i-install-and-or-run-node-red-with-an-admin-account-sudo/82402):
>
> You MAY install Node-RED using elevated privileges (e.g. using sudo on a Linux system) - this is generally required if installing as a "global" node-red install -g ..... Which many people do. You should NOT run Node-RED using a privileged account (e.g root on Linux systems). Since this is very insecure and will also almost certainly cause you many issues later on. For a low security installation, you might install globally using elevated privileges and run using the same account as you usuall…

---

<div class="post-metadata">

### Author: ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)
#### Post date: [27 October 2023 16:28 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/11 "2023-10-27T16:28:10Z")

</div>

@TotallyInformation  
Thanks for thr details. Have to look into it deeper and compare with my installation, followed this: [Running on Raspberry Pi : Node-RED](https://nodered.org/docs/getting-started/raspberrypi)

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [27 October 2023 16:34 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/12 "2023-10-27T16:34:07Z")

</div>

If you followed the documentation and used the "Raspberry pi" script to install, I believe it should have warned you about running it as root.

It's very seductive to do things as root (yes I've been there too!) But you are almost always storing up problems for further down the line.

---

<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: [27 October 2023 16:47 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/13 "2023-10-27T16:47:29Z")

</div>

> [@gNeandr](#):
>
> followed this: [Running on Raspberry Pi : Node-RED](https://nodered.org/docs/getting-started/raspberrypi)

That should setup the systemd script to run node-red as the logged in user, unless you ran the script with sudo. Have a look in /lib/systemd/system/nodered.service to see what user is specified there.

---

<div class="post-metadata">

### Author: ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)
#### Post date: [27 October 2023 17:17 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/14 "2023-10-27T17:17:24Z")

</div>

> [@Colin](#):
>
> /lib/systemd/system/nodered.service

```auto
# Run as normal pi user - change to the user name you wish to run Node-RED as
User=pi
Group=pi
WorkingDirectory=/home/pi

```

---

<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: [29 October 2023 09:53 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/15 "2023-10-29T09:53:26Z")

</div>

Assuming you are running node-red via systemd and not doing something like  
`sudo node-red`  
then I don't see how node red can write to the file XW.ini as it is only writable by root as is shown by:

> [@gNeandr](#):
>
> ```auto
> $ ls -lt *.ini
> -rw-r--r-- 1 root root 1306 Oct 27 17:01 XW.ini
> 
> ```

---

<div class="post-metadata">

### Author: ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)
#### Post date: [29 October 2023 10:32 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/16 "2023-10-29T10:32:03Z")

</div>

OK, the problem indeed is I'm running NR with sudo.  
So I have to check how to change the installation .. or better to re-install NR without sudo.  
It will take probably a few days (getting a new PV/heating system), but will report back.  
Thanks for the moment 😄

---

<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: [29 October 2023 11:54 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/17 "2023-10-29T11:54:52Z")

</div>

It isn't about how you installed node-red, it is about how you run it. The command  
`node-red-start`  
will run node-red as a systemd service, with the user/group specified in the systemd script.

---

<div class="post-metadata">

### Author: ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)
#### Post date: [29 October 2023 13:08 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/18 "2023-10-29T13:08:31Z")

</div>

Hope it's that easy.

This is all about my development NR instance. The production one has been started with `node-red-start` and also using `sudo systemctl enable nodered.service` for the automatic restart after poweroff/on.  
But that instance isn't with the root:root for writing the files.

As discussed with another blog thread for the development I'm working with  
`sudo node-red -p 2000 -u /home/pi/.red2000`  
And there is the "problem". But maybe it's solved at the moment I take over the flows to the production.

Starting NR dev without sudo there is missing uibuilder

```auto
 $ node-red -p 2000 -u /home/pi/.red2000
29 Oct 11:26:40 - [info] 

Welcome to Node-RED
===================

29 Oct 11:26:40 - [info] Node-RED version: v3.0.2
29 Oct 11:26:40 - [info] Node.js version: v18.17.1
29 Oct 11:26:40 - [info] Linux 6.1.21-v7+ arm LE
29 Oct 11:26:44 - [info] Loading palette nodes
29 Oct 11:26:56 - [error] [uibuilder:runtimeSetup] Root folder is not accessible, path: /home/pi/.red2000/uibuilder. EACCES: permission denied, access '/home/pi/.red2000/uibuilder'

```

.. etc ..

---

<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: [29 October 2023 13:26 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/19 "2023-10-29T13:26:34Z")

</div>

> [@gNeandr](#):
>
> sudo node-red -p 2000 -u /home/pi/.red2000

Almost certainly you should not be using sudo.

> [@gNeandr](#):
>
> ```auto
> 29 Oct 11:26:56 - [error] [uibuilder:runtimeSetup] Root folder is not accessible, path: /home/pi/.red2000/uibuilder. EACCES: permission denied, access '/home/pi/.red2000/uibuilder'
> 
> ```

Is that because the folder has root permissions (due to running with sudo)? If so then I suggest resetting the permissions using  
`sudo chown -R pi:pi ~/.red2000

---

<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: [28 December 2023 13:26 UTC](https://discourse.nodered.org/t/node-red-file-write-set-ownership/82398/20 "2023-12-28T13:26:39Z")

</div>

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