Adding Users in MQTT Broker

Nauman Shakir picture Nauman Shakir · Dec 30, 2016 · Viewed 14k times · Source

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)

Answer

hardillb picture hardillb · Dec 30, 2016

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.