Installing secure Mosquitto broker on Raspberry Pi along with systemd start up

Eclipse Mosquitto™ is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol versions 3.1 and 3.1.1. MQTT provides a lightweight method of carrying out messaging using a publish/subscribe model. This makes it suitable for “Internet of Things” messaging such as with low power sensors or mobile devices such as phones, embedded computers or microcontrollers like the Arduino.

This is enough for the introduction. In this tutorial we will learn “How to install mosquitto broker on Raspberry Pi. So Let’s get started  😎


Open up your favourite terminal program such as putty and connect to Raspberry Pi through ssh. Type the following commands one by one for successful installation of Mosquitto broker in your Raspberry Pi.

Using systemd start up for Mosquitto:

Mosquitto broker does not using modern system of systemd for start up. In order to move old init system, following the procedure below.

After removing old init.d script for Mosquitto broker, Create systemd unit file using Nano editor;

Paste the following contents in the Nano editor using Right mouse key.

Save the file by pressing “CTRL” and “X” key. Editor will ask for the confirmation to save the file. Press “Y” key and hit “Enter”.

Now reload systemd configuration using the following command.

Enable Mosquitto service to start at boot;

Starting Mosquitto service;

Password protecting MQTT Server:

In order to protect our Mosquitto MQTT Server, we need to create a user by issuing following command.

“pi” is the name of user which will be used in authentication process in future. By issuing the command above, system will ask to enter a password for MQTT broker. Enter the password and press Enter key, confirm it by retyping again and you have successfully completed securing your MQTT server with a password.

Mosquitto configuration:

We also have to make certain adjustment further. Create a new configuration file by using the command below.

Paste the following contents to the mosquitto configuration file by clicking Right mouse button and save the file using “CTRL” and “” key followed by “Y” and then hit enter (“Return Key”).

After adding configuration file, restart mosquitto service by issuing following commands;

Thats all, We have successfully configured our Mosquitto broker. Have fun 😎 .

Leave a Reply

Your email address will not be published. Required fields are marked *