Setting up Authentication in Mosquitto MQTT Broker

  1. Install the latest Mosquitto distribution.
wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
cd /etc/apt/sources.list.d/
sudo wget http://repo.mosquitto.org/debian/mosquitto-wheezy.list
sudo apt-get update
sudo apt-get install mosquitto
sudo stop mosquitto
sudo mosquitto_passwd -c /etc/mosquitto/passwd <user_name>
sudo gedit /etc/mosquitto/mosquitto.conf
password_file /etc/mosquitto/passwd
allow_anonymous false
  • “allow_anonymous false” is used to prevent, clients without username and password to connecting to the broker.
mosquitto -c /etc/mosquitto/mosquitto.conf
mosquitto_sub -h localhost -p 1883 -t myTopic -u <user_name> -P <password>

--

--

--

Engineer | Technology Enthusiast

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Eranda Rajapakshe

Eranda Rajapakshe

Engineer | Technology Enthusiast

More from Medium

💡NPM (Node Package Manager)

GUIDE: How To Run C Programs On Android?

How to create a Dynamic Library in C

How to Build Linux ARM32 and Aarch64 Barcode QR Scanner in Docker Container