How to change default (installation) user "pi"

Dear all,

when installing Node-RED, i did it on an raspberryPi and used the default user "pi"- Now, I disabled the login of this user and use a different user name to login for security reasons. Node-red still works fine, but:

When I use the exec node to run a shell script and write "whoami" in the script, it says "pi". How can I change this to my current user - so change the user Node-RED uses?

You will have a systemd script to run node-red. In it, there is a definition of the user that node-red runs under. You can change the user there.

Hmm.. I found /etc/systemd/system folder and there zigbee2mqtt.service, with this user in it (see below) - but nothing about Node-RED.. ?


ExecStart=/usr/bin/npm start


There will be other service files, have a look around.

That's what you will need to change.

Ok thanks, I found it; just not under /etc/systemd but /lib/systemd
Now I see what you mean / will try.

If you run
sudo systemctl status nodered
it will tell you where the service file is. Note there is no dash in nodered.

An alternative to changing it manually is to login as the new user and then run the node red install/upgrade script again. That will replace the service file with one for the correct user. It will also upgrade node red to the latest of course.

How are you making it pick up the correct .node-red folder? That is also defined in that service file via the user name.

I just copied the folder. Works fine so far.

If node red is still running as the user pi then it should be picking up the folder from /home/pi, not the new user. What I meant was how are you telling node red to use the new user's .node-red folder?

The "whoami" in the script tells now it used the new user, that I set in the nodered.service file. Which folder it uses - I didn't care as long as it works. :slight_smile:

How do you know which files to backup so you don't lose everything in case of a problem, if you don't know where they are?

If you run
It will tell you where it is.

I just make an image of the raspi's SD card. But you are right, always good to know what's going on! :slight_smile:

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