Mosquitto on a Raspberry Pi

From: How-To Get Started with Mosquitto MQTT Broker on a Raspberry Pi (YouTube)

Using putty, login to the Raspberry Pi

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install mosquitto
sudo apt-get install mosquitto-clients
Change mosquitto configuration ... require authentication ...
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
Create a user that can access mosquitto...
sudo mosquitto_passwd -c /etc/mosquitto/pwfile user-name
Password: user-password
Reboot ...
sudo reboot
To test if everything is working, open two putty connections ...
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"