andrerolfs.github.io

View on GitHub

20200331 Mosquitto Pi Setup

This is how I have setup and configured my Mosquitto server running on Raspbian Buster lite.

  1. write the Raspbian Buster lite image with win32diskimager to the SDHC card
  2. configure the Raspbian with raspi-config like I have documented here
  3. update the Raspbian packets

     sudo apt-get update
    
  4. perform the update

     sudo apt-get dist-upgrade
    
  5. install the mosquitto server according to App Code Labs Introduction to IoT: Build an MQTT Server Using Raspberry Pi

  6. verify that /etc/mosquitto/mosquitto.conf contains the line

     include_dir /etc/mosquitto/conf.d
    
  7. create a conf.ddirectory in /etc/mosquitto/

     mkdir /etc/mosquitto/conf.d
    
  8. create a password for a user with the name user in /etc/mosquitto/conf.d/

     sudo mosquitto_passwd -c mosquitto_passwordfile_user user
    
  9. create the file /etc/mosquitto/conf.d/mosquitto.conf with this content :

     allow_anonymous false
     password_file /etc/mosquitto/conf.d/mosquitto_passwordfile_user
    

At the end I have achieved this :

  1. the mosquitto server is started automatically when Raspbian is booted
  2. my /etc/mosquitto/conf.d/mosquitto.conf is included by /etc/mosquitto/mosquitto.conf
  3. the mosquitto server does not allow anonymous login anymore
  4. the only allowed user is user and you have to use the password coded in /etc/mosquitto/conf.d/mosquitto_passwordfile_user