How to set username/password mosquitto?

datnq picture datnq · Jul 1, 2015 · Viewed 35.7k times · Source

I used the mosquitto_passwd command to create a password file.

mosquitto_passwd /etc/mosquitto/passwd admin

I added the path to my password file in mosquitto.conf:

password_file /etc/mosquitto/passwd

But when i subscribe or publish it doesn't require username/password?

mosquitto_sub  -t '#' -d
Client mosqsub/19032-Dell sending CONNECT
Client mosqsub/19032-Dell received CONNACK
Client mosqsub/19032-Dell sending SUBSCRIBE (Mid: 1, Topic: #, QoS: 0)
Client mosqsub/19032-Dell received SUBACK
Subscribed (mid: 1): 0

What did I miss?

Answer

kartben picture kartben · Jul 7, 2015

By default, Mosquitto will still allow anonymous connections, i.e. connections where no username/password is provided. In addition to the password_file entry, you also need:

allow_anonymous false