mosquitto not authorised

Eclipse Mosquitto is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol versions 5.0, 3.1.1 and 3.1. Mosquitto is lightweight and is suitable for use on all devices from low power single board computers to full servers.
The MQTT protocol provides a lightweight method of carrying out messaging using a publish/subscribe model. This makes it suitable for Internet of Things messaging such as with low power sensors or mobile devices such as phones, embedded computers or microcontrollers.
The Mosquitto project also provides a C library for implementing MQTT clients, and the very popular mosquitto_pub and mosquitto_sub command line MQTT clients.

最近需要用mqtt来实现消息处理,在windows上安装Mosquitto之后,不使用用户名密码提示connection refused: not authorised。结果添加用户名密码之后还是提示同样的错误。

搜索了一下有人是安装路径问题,安装路径不能有空格。于是奔着简单粗暴的解决方式,直接重新安装。操作之后还是同样的问题,打开配置文件发现这个版本没有定义password_file,修改为:

# -----------------------------------------------------------------
# Default authentication and topic access control
# -----------------------------------------------------------------

# Control access to the broker using a password file. This file can be
# generated using the mosquitto_passwd utility. If TLS support is not compiled
# into mosquitto (it is recommended that TLS support should be included) then
# plain text passwords are used, in which case the file should be a text file
# with lines in the format:
# username:password
# The password (and colon) may be omitted if desired, although this
# offers very little in the way of security.
#
# See the TLS client require_certificate and use_identity_as_username options
# for alternative authentication options. If a plugin is used as well as
# password_file, the plugin check will be made first.
password_file E:\mosquitto\pwfile.example

并且没有定义默认监听端口,修改为(7788改成自己想要使用的端口):

# =================================================================
# Listeners
# =================================================================

# Listen on a port/ip address combination. By using this variable
# multiple times, mosquitto can listen on more than one port. If
# this variable is used and neither bind_address nor port given,
# then the default listener will not be started.
# The port number to listen on must be given. Optionally, an ip
# address or host name may be supplied as a second argument. In
# this case, mosquitto will attempt to bind the listener to that
# address and so restrict access to the associated network and
# interface. By default, mosquitto will listen on all interfaces.
# Note that for a websockets listener it is not possible to bind to a host
# name.
#
# On systems that support Unix Domain Sockets, it is also possible
# to create a # Unix socket rather than opening a TCP socket. In
# this case, the port number should be set to 0 and a unix socket
# path must be provided, e.g.
# listener 0 /tmp/mosquitto.sock
#
# listener port-number [ip address/host name/unix socket path]
listener 7788

重启服务就ok了。

遇到验证失败可以根据下面的检查内容尝试:

1.安装路径(我不确定是否和这个有关)

2.服务有没有启动

3.有没有创建用户

4.密码文件是否已经配置号

5.监听端口是否一致

☆文章版权声明☆

* 网站名称:obaby@mars
* 网址:https://h4ck.org.cn/
* 本文标题: 《mosquitto not authorised》
* 本文链接:https://h4ck.org.cn/2022/11/mosquitto-not-authorised/
* 转载文章请标明文章来源,原文标题以及原文链接。请遵从 《署名-非商业性使用-相同方式共享 2.5 中国大陆 (CC BY-NC-SA 2.5 CN) 》许可协议。


分享文章:

猜你喜欢:

2 comments

  1. Microsoft Edge 107 Microsoft Edge 107 Windows 10 Windows 10 China江苏省南京市 电信 ip address 114.221.*.*

    看不懂文章不要紧,图片就能引来绅士们的热烈讨论。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注