Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Users in MQTT Broker

Tags:

mqtt

mosquitto

I have an MQTT broker running in Ubuntu 16.04. My question is that how I can add users while the broker is running? When I add a user using

mosquitto_passwd -c /etc/mosquito/pwfile user2

The user does show up in pwfile but I am not able to access that user from an external source until I restart the broker. I have tried to use

sudo mosquitto -c /etc/mosquitto/mosquitto.conf

to reload the mosquitto.conf file but it gives this error

1483102542: Config loaded from /etc/mosquitto/mosquitto.conf.
1483102542: Opening ipv4 listen socket on port 1883.
1483102542: Error: Address already in use

So what should I do to add users to broker and load them without restarting the broker?(I am using ESP8266 devices to access this broker and I have also tried to access the newly added user using MQTTLens(a chrome extension) but I was unable to access)

like image 298
Nauman Shakir Avatar asked Dec 30 '16 13:12

Nauman Shakir


People also ask

How many clients can a MQTT broker handle?

Each one will handle 10-20 clients. As far as I understand a common solution is MQTT. The clients periodically send data to the broker (i.e. Mosquitto running on the hosting server), that in turn updates the main web app that runs on the same server.

Can a MQTT broker also be a client?

Any device that has a TCP/IP stack and is capable of using an MQTT library can become an MQTT client, that is, a publisher, a subscriber or both a publisher and a subscriber. The MQTT library makes it possible for the device to talk MQTT on top of TCP/IP and to interact with specific types of MQTT servers.

What is MQTT username and password?

Username and password authentication is common on all computer systems and the Mosquitto MQTT broker supports this authentication mechanism. To use Password authentication you need to configure the MQTT broker to require it. The username and password are sent in clear text, and you will need to use TLS to secure it.


2 Answers

There are 2 options for this.

  1. Mosquitto reads the password file when it starts so will not pick up the changes when you run mosquitto_passwd. You can force mosquitto to re-read the file by sending the mosquitto broker a HUP signal
  2. The better option is to stop using the password file if you are going to add/remove users dynamically and use the mosquitto-auth-plugin which lets you use a database to store the usernames/passwords and the ACL entries.
like image 141
hardillb Avatar answered Sep 20 '22 14:09

hardillb


You can Reload the configuration without interrupting the existing connections by sending SIGHUP to the process.

$kill -SIGHUP PID

This will reload the pwfile. But not the PID file. More information of the reloading files with HUP can be found in : mosquitto conf documentation

Complete Steps are shown here: reload mosquito config without restarting the service

like image 31
Dulaj Avatar answered Sep 18 '22 14:09

Dulaj