From: How-To Get Started with Mosquitto MQTT Broker on a Raspberry Pi (YouTube)
Using putty, login to the Raspberry Pi
Change mosquitto configuration ... require authentication ...sudo apt-get update sudo apt-get upgrade sudo apt-get install mosquitto sudo apt-get install mosquitto-clients
Create a user that can access mosquitto...sudo nano /etc/mosquitto/mosquitto.conf Remove the last line "include_dir ..." then add after the last line ... allow_anonymous false password_file /etc/mosquitto/pwfile listen 1883
Reboot ...sudo mosquitto_passwd -c /etc/mosquitto/pwfile user-name Password: user-password
To test if everything is working, open two putty connections ...sudo reboot
putty 1 - subscribe mosquitto_sub -d -u user-name -p user-password -t /dev/test .... .... .... ^c to stop subscriber putty 2 - publish mosquitto_pub -d -u user-name -p user-password -t /dev/test -m "Hello World"