Search code examples
node.jsraspberry-pinode-red

Set Node-red password in root mode


I have a node-red flow in my raspberry pi 3 for which I'd like to set a user and password in root mode, but haven't succeeded yet.

So far I've managed to set it as a regular user as stated in their own security website (https://nodered.org/docs/security), but I need to run it as admin in order to save some stuff and found out there's no guidance for such scenario (on they way found out there are two versions of Node-red in the raspberry pi, one for 'sudo start-node-red' and another one for 'start-node-red', I'm interested on the first case)

The one I've managed for the plain user would be editing the settings.js as follows:

adminAuth: {
    type: "credentials",
    users: [{
        username: "admin",
        password: "$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN.",
        permissions: "*"
    }]
}

Has anyone managed to do so?


Solution

  • There are not two versions of Node-RED installed on the Raspberry Pi - you are running it in two different ways.

    Node-RED is installed as a system service. The service can be started and stopped using node-red-start and node-red-stop commands. By default, the service will run Node-RED as the pi user, and use /home/pi/.node-red as the user directory - where the settings.js file is located.

    You can manually run Node-RED by using the node-red command. Rather than start it as a service, it will run in the terminal you ran the command in. It uses ~/.node-red as the user directory. If you run it as the Pi user, that will be /home/pi/.node-red - the same as the service instance. If you run using sudo then you are running as the root user, so the user directory will be /root/.node-red. Following from that, the settings file it will use will be /root/.node-red/settings.js - so it is that file you would need to enable adminAuth in.

    You can confirm exactly what user directory and settings file it is using by viewing the log on start up where the full paths to both of these things is provided.

    Note: we strongly recommend not running as root if you do not need to.