Node-red : file -- write & set ownership

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).

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.

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

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


$ 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?

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

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.

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


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.

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

1 Like

Thanks for thr details. Have to look into it deeper and compare with my installation, followed this: Running on Raspberry Pi : Node-RED

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.

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.

# Run as normal pi user - change to the user name you wish to run Node-RED as

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:

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 :smile:

1 Like

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

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

 $ 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 ..

Almost certainly you should not be using sudo.

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

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