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
include_dir /etc/mosquitto/conf.d
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
For more detailed information, see this video : https://youtu.be/_uFVRrQsGKU