36

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?

kartben
  • 2,485
  • 21
  • 24
datnq
  • 461
  • 1
  • 6
  • 12

3 Answers3

69

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
kartben
  • 2,485
  • 21
  • 24
0

password_file MUST not be empty. Or password is not required.

BaiJiFeiLong
  • 3,716
  • 1
  • 30
  • 28
0

Everything that was needed for me to get it working was already on this page, but scattered, so below are the complete required lines to add to the mosquitto_conf file:

listener 1883
password_file /etc/mosquitto/password_file
allow_anonymous false
sampo
  • 61
  • 4