节点红色管理员登录失败

node red admin login failed

我正在尝试按照 this tutorial 为节点 red 创建登录名。

据我所知,node-red admin 内置于 node red 中,所以我为什么需要安装软件包?使用教程代码尝试

时出现错误
npm install -g --unsafe-perm node-red-admin

Linux 终端此命令在教程代码中起作用:

node-red-admin hash-pw

要取回密码 hashsudo nano ~/.node-red/settings.js 按照教程取消注释我这边的正确行,它看起来像这样:

/** To password protect the Node-RED editor and admin API, the following
 * property can be used. See http://nodered.org/docs/security.html for details.
 */
adminAuth: {
    type: "credentials",
    users: [{
        username: "ben",
        password: "supersecretP@$$word",
        permissions: "*"
    }]
},

/** The following property can be used to enable HTTPS
 * This property can be either an object, containing both a (private) key
 * and a (public) certificate, or a function that returns such an object.
 * See http://nodejs.org/api/https.html#https_https_createserver_options_requestlistener
 * for details of its contents.
 */

然后通过 nano 写入文件并执行 sudo reboot 我无法使用此用户名和密码登录,有什么想法可以尝试吗?

此处错误:

adminAuth: {
    type: "credentials",
    users: [{
        username: "ben",
        password: "supersecretP@$$word",
        permissions: "*"
    }]
},

password 需要 hash 而不是我希望用来登录 Node Red 的密码。

您存储在 settings.js 文件中的密码应该是根据您的密码生成的 散列 。 您可以使用 cli use

中的工具生成此哈希

node-red-admin hash-pw

node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" your-password-here

输入密码后会出现一串hash,将其复制并插入到设置文件中:

adminAuth: {
    type: "credentials",
    users: [{
        username: "ben",
        password: "b$wuAqPiKJlVN27eF5qJp.RuQYuy6ZYONW7a/UWYxDTtwKFCdB8F19y",
       permissions: "*"
    }]
},

它应该看起来像这样。

我建议您在打开它供 public 使用之前深入阅读 documentation page 以正确保护您的 node-red 实例。