mosquitto_passwd -c /etc/mosquitto/pwfile.conf user
7.再次编辑配置文件
vim /etc/mosquitto/mosquitto.conf
修改以下内容:
646 # Defaults to true if no other security options are set. If `password_file` or
647 # `psk_file` is set, or if an authentication plugin is loaded which implements
648 # username/password or TLS-PSK checks, then `allow_anonymous` defaults to
649 # false.
650 #
651 #allow_anonymous true
652 allow_anonymous ture
......
666 # See the TLS client require_certificate and use_identity_as_username options
667 # for alternative authentication options. If an auth_plugin is used as well as
668 # password_file, the auth_plugin check will be made first.
669 #password_file
670 password_file /etc/mosquitto/pwfile.conf
8.使用命令发送和接受
1.打开订阅者
# 无密码
mosquitto_sub -t test
# 有密码
mosquitto_sub -u ycgl -P ycglmosquitto123 -t test
2.打开发布者
# 无密码
mosquitto_pub -t test -m "测试发送"
# 有密码
mosquitto_pub -u ycgl -P ycglmosquitto123 -t test -m "测试发送"