MQTT入门2 -- “Error: Invalid password hash for user nick.”和“Connection Refused: not authorised.”
原文地址:https://www.cnblogs.com/NickQ/p/9277315.html
问题描述:
搭建好mosqitto环境后,利用无密码验证方式,成功通过测试。
但修改配置文件将匿名访问关闭,并设置密码文件
allow_anonymous false
password_file /home/nickxq/mqtt_passwd
密码文件内容:
参考:https://mosquitto.org/man/mosquitto-conf-5.html
[nickxq@centos6 ~]$ cat ./mqtt_passwd
nick:nickxq
开启服务器报错:
[nickxq@centos6 ~]$ mosquitto -c mosquitto.conf
1530947452: mosquitto version 1.4.15 (build date 2018-04-21 17:41:08+0800) starting
1530947452: Config loaded from mosquitto.conf.
1530947452: Error: Invalid password hash for user nick.
1530947452: Error opening password file "/home/nickxq/mqtt_passwd".
提示密码无效。
猜想可能是因为文件明文密码需要加密。
猜想依据:密码示例文件如此,示例文件内容:
[nick@XQLY ~]$ cat /etc/mosquitto/pwfile.example
roger:$6$clQ4Ocu312S0qWgl$Cv2wUxgEN73c6C6jlBkswqR4AkHsvDLWvtEXZZ8NpsBLgP1WAo/qA+WXcmEN/mjDNgdUwcxRAveqNMs2xUVQYA==
sub_client:$6$U+qg0/32F0g2Fh+n$fBPSkq/rfNyEQ/TkEjRgwGTTVBpvNhKSyGShovH9KHewsvJ731tD5Zx26IHhR5RYCICt0L9qBW0/KK31UkCliw==
pub_client:$6$vxQ89y+7WrsnL2yn$fSPMmEZn9TSrC8s/jaPmxJ9NijWpkP2e7bMJLz78JXR1vW2x8+T3FZ23byJA6xs5Mt+LeOybAHwcUv0OCl40rA==
于是通过linux中用户密码shadow文件,找到用户密码
nick:$6$.KqyKaCc$om0v0xipwvVJOubJjihzCGF7yII4CGZireXCGCj7WskvlDSDwv3qfDk.GWe2/IUO4tqn5XYFR8CpekZz7oLaG/:17718:0:99999:7:::
密文串意思参考:
http://blog.sina.com.cn/s/blog_4d1f40c00101cvd8.html
https://blog.csdn.net/jinyuhongye/article/details/7950961
得到nick用户,明文密码为nickxq的加密密文为:
$6$.KqyKaCc$om0v0xipwvVJOubJjihzCGF7yII4CGZireXCGCj7WskvlDSDwv3qfDk.GWe2/IUO4tqn5XYFR8CpekZz7oLaG/
将密文添加到 ./mqtt_passwd
[nickxq@centos6 ~]$ cat ./mqtt_passwd
nick:$6$.KqyKaCc$om0v0xipwvVJOubJjihzCGF7yII4CGZireXCGCj7WskvlDSDwv3qfDk.GWe2/IUO4tqn5XYFR8CpekZz7oLaG/
运行服务器监听程序
[nickxq@centos6 ~]$ mosquitto -c mosquitto.conf
1530948296: mosquitto version 1.4.15 (build date 2018-04-21 17:41:08+0800) starting
1530948296: Config loaded from mosquitto.conf.
1530948296: Opening ipv4 listen socket on port 1885.
1530948296: Opening ipv6 listen socket on port 1885.
服务器程序开始监听,正常。
mosquitto 密码文件中,密文确实需要加密
** 以为问题解决了么?! NO,没有 。不信? 继续看**
此时,建立订阅者和发布者
[nickxq@centos6 ~]$ mosquitto_sub -p 1885 -u nick -P nickxq -t "test"
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
^C
[nickxq@centos6 ~]$ mosquitto_pub -p 1885 -u nick -P nickxq -t test -m "Hello。"
Connection Refused: not authorised.
Error: The connection was refused.
[nickxq@centos6 ~]$
不论哪个客户端,都会提示错误 Refused: not authorised. 。
显然,这是密码不正确。可能的原因有很多,最容易想的就是加密方式,linux用户密码生成和mosquitto采用的方法不同。
那么,如何得到一个正确的密文串呢。
通过查看手册,知道了mosquitto_passwd程序
可以使用mosquitto_passwd程序,自动生成
但是,问题是 command not found
[nickxq@centos6 ~]$ mosquitto_passwd --help
-bash: mosquitto_passwd: command not found
这个问题原因我没找到,但是我重新下载编译了mosquitto-1.4.15,就有了mosquitto_passwd
[nickxq@centos6 ~]$ mosquitto
mosquitto mosquitto_passwd mosquitto_pub mosquitto_sub
[nickxq@centos6 ~]$ mosquitto_passwd --help
mosquitto_passwd is a tool for managing password files for mosquitto.
Usage: mosquitto_passwd [-c | -D] passwordfile username
mosquitto_passwd -b passwordfile username password
mosquitto_passwd -U passwordfile
-b : run in batch mode to allow passing passwords on the command line.
-c : create a new password file. This will overwrite existing files.
-D : delete the username rather than adding/updating its password.
-U : update a plain text password file to use hashed passwords.
See http://mosquitto.org/ for more information.
这里使用 -U 将已有的明文更改为密文
[nickxq@centos6 ~]$ vim ./mqtt_passwd
nick:nickxq
[nickxq@centos6 ~]$ mosquitto_passwd -U ./mqtt_passwd
[nickxq@centos6 ~]$ cat ./mqtt_passwd
nick:$6$U3Ln7cn3+tKv0UVG$IU+jS8lPN9iH9N49u7t/eseOOKdvt8cvFjIOXrBo3LPMhf7YidcFubugPGjKOXDkjriiZdRnszb83LNLheVmlw==
当然,也可以直接向文件中写入一个新的用户名和密码
[nickxq@centos6 ~]$ touch mqtt_passwd
[nickxq@centos6 ~]$ mosquitto_passwd -b mqtt_passwd nick nickxq
原文地址:https://www.cnblogs.com/NickQ/p/9277315.html
本帖完
MQTT入门2 -- “Error: Invalid password hash for user nick.”和“Connection Refused: not authorised.”的更多相关文章
- 运行SparkStreaming的NetworkWordCount实例出错:Error connecting to localhost:9999 java.net.ConnectException: Connection refused 解决办法
一.背景 首先按照Spark的官方文档来运行此实例,具体方法参见这里,当运行命令$ nc -lk 9999开启端口后,再运行命令$ ./bin/run-example streaming.Networ ...
- docker 错误:Error response from daemon: cannot stop container: connect: connection refused": unknown
docker 错误:Error response from daemon: cannot stop container: 795e4102b2de: Cannot kill container 795 ...
- ubuntu Error fetching https://gems.ruby-china.org/: Errno::ECONNREFUSED: Connection refused
排除网络原因的前提下 是 权限问题 用 sudo 来 执行命令即可 sudo gem sources -a https://gems.ruby-china.org/
- mysql 错误 ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number 解决办法
MySQL创建用户(包括密码)时,会提示ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number: 问题原因: ...
- ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number;
rpm 安装了 mysql 5.6 的版本 遇到的问题 1. 提示与5.1版本的有冲突. 解决方式, 是 rpm --force -ivh rpm包.rpm 进行强制安装 2. 启动 mysql 后, ...
- MQTT入门1 -- mosquitto 安装
原文链接:https://www.cnblogs.com/NickQ/p/9247638.html MQTT入门1 -- mosquitto 安装 简介: MQTT(Message Queuing T ...
- ORA-00988: missing or invalid password(s)
创建账号或修改账号密码时有可能会遇到ORA-00988: missing or invalid password(s),那么什么情况下会遇到这种错误呢? 一般是因为密码的设置不符合命名规范: 1:密码 ...
- Java:Linux上java -jar xxx.jar命令执行jar包时出现Error: Invalid or corrupt jarfile xxx.jar解决方案
背景: 从ftp上上传jar包到linux上,之后在linux上通过ftp命令下载jar包文件,开始执行Java-jar,一直提示错误:Error: Invalid or corrupt jarfil ...
- 数据库里账号的密码,需要怎样安全的存放?—— 密码哈希(Password Hash)
最早在大学的时候,只知道用 MD5 来存用户的账号的密码,但其实这非常不安全,而所用到的哈希函数,深入挖掘,也发现并不简单-- 一.普通的 Hash 函数 哈希(散列)函数是什么就不赘述了. 1.不推 ...
随机推荐
- 存储过程存储过程需要用两个'',先where再Group,再Order by
存储过程需要用两个'',先where再Group,再Order by 未完,待续
- SpringMVC与shiro集成及配置文件说明!
在项目中xml文件的配置是必不可少的,特别是SpringMVC框架.但是几乎所有项目的配置都是大同小异,很多人都是直接复制黏贴了事,不少人对其具体含义及用途都不甚全知.本片文章将正对项目中常用的框架S ...
- MVC项目后台管理,各页面判断登陆问题。
public class BaseController : Controller { protected string hostUrl = ""; /// <summary& ...
- Python学习---Django的基础操作180116
Django创建数据库操作 django流程之model实例 settigs.py:更改Django2.0.1的配置,更新为之前的路径配置 'DIRS': [os.path.join(BASE_DIR ...
- windows下sqli-labs的搭建及学习(GET篇)
环境搭建: 源码下载地址:https://github.com/Audi-1/sqli-labs 需要搭建以下环境: apache+mysql+php Tomcat+mysql+java(部分关卡需要 ...
- Azure 登录设置
转自 http://blog.csdn.net/azure_nonofficial/article/details/38095459 这是我们Azure非官方的第一篇博文,欢迎大家各种拍砖. 微软云计 ...
- Permission Denial: opening provider 隐藏的android:exported属性的含义
Permission Denial: opening provider 隐藏的android:exported属性的含义 2013-03-07 13:17 227人阅读 评论(0) 收藏 举报 场景: ...
- 在CentOS7上安装和使用ZooKeeper最新版本(V3.4.12)
0.ZooKeeper文档 http://zookeeper.apache.org/doc/r3.4.11/zookeeperOver.html 1.准备 在CentOS7上安装zookeeper时, ...
- c++抽象类,纯虚函数
- iOS 技能分类:
1.语言与系统: 2.架构与机制: 3.性能:cpu.gpu.io.缓存.内存:性能监测工具: 4.知名开源库: