Update & Upgrade RPI.
sudo apt-get update sudo apt-get upgrade
Install Mosquitto mqtt broker and Subscriber
sudo apt-get install mosquitto -y sudo apt-get install mosquitto-clients -y
Open Mosquitto.conf File
sudo nano /etc/mosquitto/mosquitto.conf
Delete the following line in the file opened
Paste the following lines to replace the deleted line
allow_anonymous false password_file /etc/mosquitto/pwfile listener 1883
save&exit the nano editor
Now you can add your username with this command. Type in your username in the section called “username”.
sudo mosquitto_passwd -c /etc/mosquitto/pwfile "username"
For example like this.
sudo mosquitto_passwd -c /etc/mosquitto/pwfile fatih