Mosquitto Guides

Create users on the broker

By default, MQTT accounts are registered via the PureLife Cloud. Under certain circumstances, however, it may be necessary or desirable to partially register to be carried out by the MQTT broker.

This is necessary, for example, when using sensors with a version lower than 0.36.

Debian/Linux

# Set variables
MQ_USER="username"
MQ_PASS=`/etc/mosquitto/pw_hasher -p cleartext-password`

# Save password and ACL
echo "$MQ_USER:$MQ_PASS" >> /etc/mosquitto/passwd
printf "$MQ_USER\ntopic #\n\n" >> /etc/mosquitto/acl

# Remove variables
unset MQ_PASS
unset MQ_USER

Docker

# Assuming you are in the purelife-cloud-docker directory.
GEN_HASH="docker run --name mqtt_passwd --rm -i -t iegomez/mosquitto-go-auth:latest-mosquitto_2.0.14 /mosquitto/pw -p"
MQ_USER="username"
MQ_PASS=`$GEN_HASH cleartext-password`

# Save password and ACL
echo "$MQ_USER:$MQ_PASS" >> ./volumes/mosquitto/passwd
printf "user $MQ_USER\ntopic #\n\n" >> ./volumes/mosquitto/acl

# Alternatively as root user
echo "$MQ_USER:$MQ_PASS" | sudo tee -a ./volumes/mosquitto/passwd
printf "user $MQ_USER\ntopic #\n\n" | sudo tee -a ./volumes/mosquitto/acl

# Remove variables
unset MQ_PASS
unset MQ_USER

Manage MQTT users with the PureLife Cloud

# Add user
{bin_dir}/purelife-cloud mqtt auth-add username password

# Remove user
{bin_dir}/purelife-cloud mqtt auth-remove username