Mosquitto username password

  • by

What you will learn here about mosquitto username password:

  • mosquitto username password or MQTT username password

In order to add security to the MQTT broker, we need to add mosquitto username password or MQTT username password.

If you want to know how to secure mosquitto on Raspberry pi, Linux system and Google cloud please click on below link.

MQTT Username Password

Mosquitto username password

Please follow the following steps to know how to add username and password to mosquitto or MQTT broker.

1)In order to add username and password to the MQTT broker, you need a MQTT broker. If you don’t know how to install MQTT broker please click on the below link.

Install MQTT Broker on Windows

2)Assuming you have installed MQTT broker.

3)Now please open the command prompt in Administrator mode which is shown below.

4)Navigate to your MQTT broker installed folder or path. For navigation use the following command

cd c:\Program Files (x86)\mosquitto

5)Execute the following command to create username and password file which is shown below

mosquitto_passwd -c “c:\Program Files (x86)\mosquitto\pass” username

6)Now enter the password which is shown below

7)Now please go to mosquitto installed folder which is shown below

8)Open mosquitto.conf file with any editor

9)Add the following lines with respect to your username and password file which is shown below

allow_anonymous false
password_file usrname_pwd_file_path

10)Now we need to restart mosquitto.

11)Now please execute the following command to stop mosquitto. Please make sure that command prompt is opened in administrator mode

net stop mosquitto

12)Now please execute the following command to stop mosquitto.

net start mosquitto

13)Now execute the following command to publish data from windows command prompt with username and password.

mosquitto_pub -t test -h localhost -m ho -u joker -P joker

14)You will receive Connection error: Connection Refused: not authorised error when either username or password or both are wrong.

Please click on the below link to become master in MQTT.

Master MQTT Protocol