mosquitto - user/passwd

【基本介绍】
这里介绍给mosquitto服务端,客户端,topic添加用户和密码等

【基本配置】
配置mosquitto.conf配置文件

allow_anonymous false #不允许匿名

password_file /etc/mosquitto/passwd #配置用户密码文件

acl_file /etc/mosquitto/acl #配置topic和用户


用htpasswd配置passwd文件
mosquitto_passwd -c /etc/mosquitto/passwd pub_client
mosquitto_passwd /etc/mosquitto/passwd sub_client
[code="linux"]
# cat /etc/mosquitto/passwd
sub_client:$6$lHiPm6dLpaqsdfQb$SETYv2TthcgK388atPA7jNTSQYlWZzz8HxRzOVeZMx5iVNAAViuHhIgYzayl5BmzjNo8C0Cf4CH6ss6LdWtW8Q==
pub_client:$6$NDYKXj+h1wb5rIsz$Mf1Hq+EEsmXXy1Y377Rt8S4oVfm3S06R6Km3rqzzOQYIKCIDz8z5vVFh8CHGx4zPnBRMWObNnFvOYVjnOe2Sdw==
[/code]

配置acl,topic和用户的关系
[code="linux"]
# cat /etc/mosquitto/acl
#This only affects clients with username "pub_client".
user pub_client
topic write mtopic/#

# This only affects clients with username "sub_client".
user sub_client
topic read mtopic/#
[/code]

【测试验证】
服务端:
[code="linux"]
# mosquitto_pub -t mtopic -m "test"
1416301592: New connection from ::1 on port 1883.
Connection Refused: not authorised.

# mosquitto_pub -t mtopic -u pub_client -P test -m "test"
1416301643: New connection from ::1 on port 1883.
1416301643: New client connected from ::1 as mosqpub/4113-sparkVM (c1, k60, upub_client).
[/code]

客户端:
[code="linux"]
# mosquitto_sub -h 192.168.197.128 -t mtopic
Connection Refused: not authorised.

# mosquitto_sub -h 192.168.197.128 -t mtopic -u sub_client -P sub_client
test
[/code]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值