Last active
October 1, 2022 13:25
-
-
Save 7wells/d0d7ba1c51386dc617ef7721e3398e04 to your computer and use it in GitHub Desktop.
Installing mosquitto broker on Raspberry Pi OS and enable remote access with user/password authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to install mosquitto broker on Raspberry Pi OS and to enable remote access/authentication | |
# | |
# Source: https://randomnerdtutorials.com/how-to-install-mosquitto-broker-on-raspberry-pi/ | |
# | |
# Install mosquitto broker (optionally also install mosquitto clients) | |
# | |
sudo apt install mosquitto mosquitto-clients | |
# Test mosquitto broker installation | |
# | |
mosquitto -v | |
# Configure mosquitto service to automatically start on Raspberry Pi boot | |
# | |
sudo systemctl enable mosquitto.service | |
# Enable remote access/authentication with user/password authentication | |
# | |
# Provide password for mosquitto user (can be different than Raspberry Pi user) | |
# parameter -c creates a new password file and overwrites existing one! | |
# e.g. sudo mosquitto_passwd -c /etc/mosquitto/passwd YOUR_USERNAME (replace YOUR_USERNAME by desired username) | |
# | |
sudo mosquitto_passwd -c /etc/mosquitto/passwd pi | |
# Edit mosquitto config to only allow authentication with username/password | |
# | |
sudo nano /etc/mosquitto/mosquitto.conf | |
# Add as first(!) line (else, it will not work) in /etc/mosquitto/mosquitto.conf the following: | |
# | |
per_listener_settings true | |
# Add below (or at the bottom) in /etc/mosquitto/mosquitto.conf the following: | |
# | |
allow_anonymous false | |
listener 1883 | |
password_file /etc/mosquitto/passwd | |
# Restart mosquitto service for changes to take effect | |
# | |
sudo systemctl restart mosquitto | |
# Check that mosquitto service is running | |
# | |
sudo systemctl status mosquitto | |
# Optional, to add more mosquitto users, e.g. user sara | |
# note to omit -c parameter as it would create new password file and overwrite existing one | |
# | |
sudo mosquitto_passwd /etc/mosquitto/passwd sara |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment