mosquitto設置用戶名和密碼


https://blog.csdn.net/qq_22111417/article/details/84142509

7、設置用戶名和密碼

找到用戶密碼文件在安裝bin下:

 

      1: 打開mosquitto.conf文件,找到allow_anonymous節點,這個節點作用是,是否開啟匿名用戶登錄,默認是true。打開此項配置(將前面的 # 號去掉)之后將其值改為true

    修改前:#allow_anonymous

    修改后:allow_anonymous false

  2: 找到password_file節點,這個節點是告訴服務器你要配置的用戶將存放在哪里。打開此配置並指定pwfile.example文件路勁(注意是絕對路勁)

    修改前:#password_file

    修改后:password_file /etc/mosquitto/pwfile.example (這里的地址根據自己文件實際位置填寫)

  3: 創建用戶名和密碼、打開命令窗口 鍵入如下命令:  

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
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM