Ubuntu Linux

How to Install Eclipse Mosquitto MQTT on Ubuntu

Richard
Written by
Richard
May 6, 2023 Updated Apr 18, 2026 2 min read

This article explains how to install the Eclipse Mosquitto MQTT message broker on Ubuntu Linux in 2026. Eclipse Mosquitto MQTT is an open-source, lightweight tool that lets devices talk to each other. It uses the MQTT protocol, which is perfect for small gadgets and big servers alike.

Why use this? It provides a simple way for devices to send and receive data. What happens when done? You will have a secure, running message broker ready to handle communication for your projects.

Install Mosquitto packages

To get the latest features and security updates, you should use the official developer repository. Follow these steps to install the software.

First, add the official Mosquitto PPA and update your system:

sudo add-apt-repository ppa:mosquitto-dev/mosquitto-ppa
sudo apt update
sudo apt install mosquitto mosquitto-clients

Once installed, check that the service is running:

sudo systemctl enable mosquitto
sudo systemctl start mosquitto
sudo systemctl status mosquitto

MQTT Explorer interface connected to an Eclipse Mosquitto MQTT broker

Setup authentication

By default, the server is open to anyone. You must secure it. Do not use plain text passwords. Instead, use modern authentication methods or encrypted files.

First, create an admin user:

sudo mosquitto_passwd -c /etc/mosquitto/.passwd superadmin

Next, configure the server to save your data if it restarts. Open the configuration file:

sudo nano /etc/mosquitto/mosquitto.conf

Add these lines to the bottom of the file:

persistence true
persistence_location /var/lib/mosquitto/

Now, create an authentication file at /etc/mosquitto/conf.d/auth.conf and add these lines:

listener 1883
allow_anonymous false
password_file /etc/mosquitto/.passwd

To encrypt your traffic, you should set up TLS/SSL certificates. Create a directory for your certificates and generate a DH parameter file:

sudo mkdir -p /etc/mosquitto/certs
sudo openssl dhparam -out /etc/mosquitto/certs/dhparam.pem 2048

You can obtain SSL certificates from a provider like Let’s Encrypt How to create self-signed certificates in Ubuntu Linux. Once you have your certificates, add them to your ssl.conf file to ensure all data is encrypted during transit.

Restart the service to apply changes:

sudo systemctl restart mosquitto

Test that your authentication works by sending a message:

sudo mosquitto_pub -h localhost -t "test" -m "Hello" -u "superadmin" -P "your_password"

Conclusion

You now have a secure MQTT broker running on Ubuntu. By using the official PPA, you stay updated. By using persistence and authentication, you keep your data safe and reliable. What happens when done? Your devices can now communicate securely across your network.

Was this guide helpful?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

Leave a Reply

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

Exit mobile version