https://blog.csdn.net/qq_22111417/article/details/84142509服务器
七、设置用户名和密码ui
找到用户密码文件在安装bin下:.net
1: 打开mosquitto.conf文件,找到allow_anonymous节点,这个节点做用是,是否开启匿名用户登陆,默认是true。打开此项配置(将前面的 # 号去掉)以后将其值改成trueblog
修改前:#allow_anonymousit
修改后:allow_anonymous false登录
2: 找到password_file节点,这个节点是告诉服务器你要配置的用户将存放在哪里。打开此配置并指定pwfile.example文件路劲(注意是绝对路劲)配置
修改前:#password_filefile
修改后:password_file /etc/mosquitto/pwfile.example (这里的地址根据本身文件实际位置填写)密码
3: 建立用户名和密码、打开命令窗口 键入以下命令: qq
mosquitto_passwd -c /etc/mosquitto/pwfile.example admin
提示连续两次输入密码、建立成功。命令解释: -c 建立一个用户、/etc/mosquitto/pwfile.example 是将用户建立到 pwfile.example 文件中、admin 是用户名。
4: 建立mosquitto用户。在命令窗口键入以下命令:
mosquitto_passwd /etc/mosquitto/pwfile.example mosquitto
一样连续会提示连续输入两次密码。注意第二次建立用户时不用加 -c 若是加 -c 会把第一次建立的用户覆盖。
至此两个用户建立成功,此时若是查看 pwfile.example 文件会发现其中多了两个用户。
mosquitto_sub.exe -h 127.0.0.1 -p 1883 -u admin -P 111 --cafile G:/mosquitto/InstallMosquitto/OpenSSL-Win64/bin/ca.crt -v -t #mosquitto_pub.exe -h 127.0.0.1 -p 1883 -u admin -P 111 --cafile G:/mosquitto/InstallMosquitto/OpenSSL-Win64/bin/ca.crt -t topic -m "hello world"mosquitto.exe -v -c mosquitto.conf--------------------- 做者:qq_22111417 来源:CSDN 原文:https://blog.csdn.net/qq_22111417/article/details/84142509 版权声明:本文为博主原创文章,转载请附上博文连接!