MQTT Username Password

What you will learn here about MQTT Username Password:

  • How to secure MQTT  broker on Raspberry PI using Username and Password
  • How to secure MQTT  broker on Linux system using Username and Password
  • How to secure MQTT  broker on Google Cloud using Username and Password
Note:
You need to follow same steps to secure your MQTT broker on Raspberry PI, Linux system as well as Google Cloud.

If you want to know how to secure MQTT broker on windows system please click on below link.

Mosquitto username password



MQTT 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.

Steps to Install MQTT Broker on Raspberry Pi

Steps to install MQTT Broker on Linux

Steps to Install MQTT Broker on Google Cloud

2)Assuming you have installed MQTT broker.

3)Now please open the Raspberry pi terminal or Linux system terminal or Google Cloud SSH Terminal

4)Please execute the following command to navigate in the mosquitto installed path

cd /etc/mosquitto


5)Now please execute the following command to create username and password file which is shown below.

sudo mosquitto_passwd -c /etc/mosquitto/pass test


6)Now please enter the password. you can enter anything as your password which is shown below.





7)Now please execute the following command to check the created username and password file which is shown below

ls


8)Now please execute the following command to modify mosquitto.conf file

sudo nano mosquitto.conf

9)Now please add following lines in mosquitto.conf file which is shown below.

allow_anonymous false
password_file /etc/mosquitto/pass


10)Now we need to restart mosquitto. Now please execute the following command to stop the mosquitto which is shown below.

sudo service mosquitto stop


11)Now please execute the following command to start the mosquitto which is shown below.

sudo service mosquitto start


12)Now please execute the following command to publish data from the terminal using username and password which is shown below.

mosquitto_pub -t test -u test -P test -m hi


13)Now please execute the following command to publish data from the terminal using the wrong username and password and you will get the connection was refused error because username and password are wrong which is shown below.

mosquitto_pub -t test -u test -P tet -m hi


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

Master MQTT Protocol

You may also like...

Leave a Reply