如何设置username/password蚊子?

How to set username/password mosquitto?

我使用 mosquitto_passwd 命令创建了一个密码文件。

mosquitto_passwd /etc/mosquitto/passwd admin

我在 mosquitto.conf 中添加了密码文件的路径:

password_file /etc/mosquitto/passwd

但是当我订阅或发布时不需要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

我错过了什么?

默认情况下,Mosquitto 仍将允许匿名连接,即未提供 username/password 的连接。 除了password_file条目外,您还需要:

allow_anonymous false

在/etc/mosquitto/mosquitto.conf中修改"allow_anonymous false"后,没有密码的用户仍然可以发布和订阅

password_file 不能为空。或者不需要密码。