# Push MQTT Credentials

**URL:** <https://discourse.nodered.org/t/push-mqtt-credentials/3969>\
**Category:** Dashboard\
**Created:** [14 October 2018 09:15 UTC](https://discourse.nodered.org/t/push-mqtt-credentials/3969 "2018-10-14T09:15:59Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![iotteknoloji](https://avatars.discourse-cdn.com/v4/letter/i/71e660/32.png) [@iotteknoloji](https://discourse.nodered.org/u/iotteknoloji)\
**Post date:** [14 October 2018 09:15 UTC](https://discourse.nodered.org/t/push-mqtt-credentials/3969/1 "2018-10-14T09:15:59Z")

</div>

Hi, I need connect a mqtt broker as client.  
But I want take credentials information from form.  
How can I set server cred?.

Can you help me?

---

<div class="post-metadata">

**Author:** ![SerVian](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@SerVian](https://discourse.nodered.org/u/SerVian)\
**Post date:** [14 October 2018 10:31 UTC](https://discourse.nodered.org/t/push-mqtt-credentials/3969/2 "2018-10-14T10:31:35Z")

</div>

I have same problem please help

---

<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:** [14 October 2018 10:51 UTC](https://discourse.nodered.org/t/push-mqtt-credentials/3969/3 "2018-10-14T10:51:07Z")

</div>

Can you please expand on the question a little. It isn't quite clear.

---

<div class="post-metadata">

**Author:** ![SerVian](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@SerVian](https://discourse.nodered.org/u/SerVian)\
**Post date:** [14 October 2018 11:01 UTC](https://discourse.nodered.org/t/push-mqtt-credentials/3969/4 "2018-10-14T11:01:47Z")

</div>

I don't want set mqtt server username and password in flow. I have form in dashboard, I want enter MQTT username and password on form. When I click submit connect.

---

<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:** [14 October 2018 11:05 UTC](https://discourse.nodered.org/t/push-mqtt-credentials/3969/5 "2018-10-14T11:05:23Z")

</div>

> [@SerVian](#):
>
> I don't want set mqtt server username and password in flow. I have form in dashboard, I want enter MQTT username and password on form. When I click submit connect.

I don't think that will work because the MQTT broker connections are made at Node-RED startup. So by the time anyone could interact via a Dashboard or other web page, the connection is long made.

If you really need to have per-user connections, you will need to set an operating system environment variable before (or as) Node-RED is started and then use that in the MQTT configuration node.

---

<div class="post-metadata">

**Author:** ![SerVian](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@SerVian](https://discourse.nodered.org/u/SerVian)\
**Post date:** [14 October 2018 11:10 UTC](https://discourse.nodered.org/t/push-mqtt-credentials/3969/6 "2018-10-14T11:10:43Z")

</div>

Can't I execute this? with msg payload?

[  
{  
"id":"2c6873d2.992abc",  
"type":"mqtt out",  
"z":"eda2a949.74ea98",  
"name":"",  
"topic":"#",  
"qos":"",  
"retain":"",  
"broker":"407a01e4.6b637",  
"x":330,  
"y":80,  
"wires":[]  
},  
{  
"id":"407a01e4.6b637",  
"type":"mqtt-broker",  
"z":"",  
"broker":"192.168.1.26",  
"port":"107",  
"clientid":"",  
"usetls":false,  
"compatmode":true,  
"keepalive":"60",  
"cleansession":true,  
"willTopic":"",  
"willQos":"0",  
"willPayload":"",  
"birthTopic":"",  
"birthQos":"0",  
"birthPayload":"",  
"credentials": {  
"user": "Admin",  
"password": "iot2018."  
}  
}  
]

---

<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:** [14 October 2018 11:58 UTC](https://discourse.nodered.org/t/push-mqtt-credentials/3969/7 "2018-10-14T11:58:51Z")

</div>

That has hard-coded user credentials. That's fine because, as Node-RED starts up, it starts the broker client connection with those credentials. You can't pass credentials dynamically - however, you can sometimes replace fixed text in a node config with `{osEnvVarName}`. Where `osEnvVarName` is the name of an operating system environment variable that you set either before Node-RED starts or possibly within the `settings.js` file (not sure if that works, I think it does).

Either way though, this is set at startup time, not dynamically.

---

<div class="post-metadata">

**Author:** ![SerVian](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@SerVian](https://discourse.nodered.org/u/SerVian)\
**Post date:** [14 October 2018 12:03 UTC](https://discourse.nodered.org/t/push-mqtt-credentials/3969/8 "2018-10-14T12:03:13Z")

</div>

Thanks for reply... ☹ Can you propose any mqtt dahsboard.

---

<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:** [14 October 2018 12:07 UTC](https://discourse.nodered.org/t/push-mqtt-credentials/3969/9 "2018-10-14T12:07:33Z")

</div>

> [@SerVian](#):
>
> any mqtt dahsboard

Again, it isn't clear what you mean. What are you trying to achieve?

If you want a "raw" view of what is happening with your MQTT broker(s), try MQTT Spy. It is a Java-based MQTT client tool.

But Node-RED can absolutely be used as a Dashboard for MQTT - just not quite as you envisaged it. The "user" credentials are actually at the device/Node-RED server level rather than the actual user. So set up credentials for each instance of Node-RED that you want to run instead of for each actual user using Node-RED.

---

<div class="post-metadata">

**Author:** ![knowledgeshark](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knowledgeshark/32/4820_2.png) [@knowledgeshark](https://discourse.nodered.org/u/knowledgeshark)\
**Post date:** [22 January 2022 22:58 UTC](https://discourse.nodered.org/t/push-mqtt-credentials/3969/10 "2022-01-22T22:58:57Z")

</div>

> [@TotallyInformation](#):
>
> s a Dashboard for MQTT - just not

I've been looking at how to update MQTT credentials as well and I believe nodered can achieve this. Each new user would require a new password, and the ability to modify the password. I've been using **mosquitto** with tools for password file management (mosquitto\_passwd).

1. On UNIX and Linux, the configuration files will be re-read by the MQTT broker (like mosquitto) if a command " **pkill -HUP mosquitto**" is run.

2. It should be possible to update the password and acl files (topic permissions) from nodered. (Their file locations are specified by mosquitto.conf)

My plan is to update those two files and then send the -HUP signal to my MQTT broker.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 January 2022 23:25 UTC](https://discourse.nodered.org/t/push-mqtt-credentials/3969/11 "2022-01-22T23:25:31Z")

</div>

If you are trying to set the username / password of the MQTT connection, the last updates to the MQTT nodes now support `msg.action` - one of which is `"connect"` and you can provide connection details in the `msg.broker`

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/c/8c697d45f5c18b20c647f2f4304d97ee0d0a312c.png)

---

<div class="post-metadata">

**Author:** ![knowledgeshark](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knowledgeshark/32/4820_2.png) [@knowledgeshark](https://discourse.nodered.org/u/knowledgeshark)\
**Post date:** [23 January 2022 00:30 UTC](https://discourse.nodered.org/t/push-mqtt-credentials/3969/12 "2022-01-23T00:30:16Z")

</div>

UPDATE: the task (Push MQTT Credentials) is to add users and update passwords of the MQTT broker. The mqtt-broker can only specify the passwords and topics to publish or subscribe.

That options looks interesting. I assume this is for where nodered is actually acting as the MQTT broker, versus a client? What MQTT node are you showing? I just checked and searching MQTT finds 75+ nodes. I've only used `node-red-contrib-mqtt-broker`.

I don't see how a client of MQTT (eg nodered) can manage the passwords of another MQTT server.

I did successfully write an `exec` node that updates the password file, appends to the acl file, and sends -HUP to the mosquitto broker.

thanks.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 January 2022 00:55 UTC](https://discourse.nodered.org/t/push-mqtt-credentials/3969/13 "2022-01-23T00:55:33Z")

</div>

> [@knowledgeshark](#):
>
> UPDATE: the task is to add users and update passwords of the MQTT broker.

Thats not how i read the OP...

> [@iotteknoloji](#):
>
> Hi, I need connect a mqtt broker as client.  
> But I want take credentials information from form.

.. I see someone who wants to set MQTT client connection credentials from a dashboard **form**.  
which is why i wrote ...

> [@Steve-Mcl](#):
>
> the last updates to the MQTT nodes now support `msg.action` - one of which is `"connect"` and you can provide connection details in the `msg.broker`

  
  

> [@knowledgeshark](#):
>
> That options looks interesting. I assume this is for where nodered is actually acting as the MQTT broker,

No, the connect action is for node-red MQTT node to connect to a broker.

  
  

Perhaps we have crossed wires. Since this post is over 3 years old & lots has changed since then, i suggest a new post with a relevant title and details of what you are aiming to achieve would sensible.

---

<div class="post-metadata">

**Author:** ![knowledgeshark](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knowledgeshark/32/4820_2.png) [@knowledgeshark](https://discourse.nodered.org/u/knowledgeshark)\
**Post date:** [23 January 2022 01:02 UTC](https://discourse.nodered.org/t/push-mqtt-credentials/3969/14 "2022-01-23T01:02:00Z")

</div>

As I mentioned, the nodered mqtt is for a client of some external MQTT broker. There is usually no way for "clients" to update MQTT Credentials (e.g. passwords).

Clarification: I'm using "MQTT Credentials" to mean adding new users. On re-reading, I think they poster mean to add the user password to connect to a broker. My quest is for adding new users.

This challenge still exists 3 years later.

And yes, updating the credentials from a dashboard form is a good approach (but not the only way, as an MQTT message could trigger the same operations).

I'm having success with an exec node performing these actions (since the MQTT broker is run on the same computer).

thanks,

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 January 2022 01:09 UTC](https://discourse.nodered.org/t/push-mqtt-credentials/3969/15 "2022-01-23T01:09:01Z")

</div>


