如何设置Mosquitto的用户名/密码?

36

我使用 mosquitto_passwd 命令来创建密码文件。

mosquitto_passwd /etc/mosquitto/passwd admin

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

但是当我订阅或发布时,它不需要用户名/密码?

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

我错过了什么?
3个回答

70

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

allow_anonymous false

3
如果这个回答对您有帮助,请不要忘记点赞并接受它。谢谢! - kartben
7
@datnq,差不多两年过去了,请别忘了接受 :) - A.W.

1

我需要让它工作的所有内容都已经在这个页面上了,但是分散在各处,因此以下是完整所需的行添加到mosquitto_conf文件中:

listener 1883
password_file /etc/mosquitto/password_file
allow_anonymous false

0

password_file 必须不为空。或者密码不是必需的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接