mosquitto -- 权限配置
2024-10-19 07:42:44
Mosquitto 权限是根据 topic 控制的、类似与目录管理。您可以设定每个用户订阅/发布权限、也可以设定每个用户可访问的topic范围、从而达到权限控制的目的。
这里我们需要我另外一个帖子(用户配置)创建的2个用户(admin/mosquitto)。
1: 给这两个用户配置不同的权限
admin 设置为订阅权限,并且只能访问的主题为"root/topic/#"
mosquitto 设置为发布权限,并且只能访问的主题为"root/topic/#"
如果用 admin 进行发布是不会成功的、反过来用 mosquitto 进行订阅同样不会接受到任何信息。因为他们的权限不同。
2: 增加权限配置
打开配置文件 aclfile.example 在其中添加如下配信息。
user admin
topic read root/topic/#
user mosquitto
topic write root/topic/#
aclfile.example内容如下:
# This affects access control for clients with no username.
topic read $SYS/# # This only affects clients with username "roger".
user roger
topic foo/bar # This affects all clients.
pattern write $SYS/broker/connection/%c/state # This is a bridge user.
user hthl_bridge
topic/# user admin
topic read root/topic/#
user mosquitto
topic write root/topic/#
mosquitto.conf中对应内容
# 服务进程的PID
pid_file /var/run/mosquitto.pid
# 服务进程的系统用户
user mosquitto
# 服务绑定的IP地址
bind_address centoshostnameKL3
# 服务绑定的端口号
port 1883
# 允许的最大连接数,-1表示没有限制
max_connections -1
# 允许匿名用户true
allow_anonymous false
# # 用户/密码文件,默认格式:username:password
password_file /etc/mosquitto/pwfile
# # 配置用户访问控制
acl_file /etc/mosquitto/aclfile
/etc/mosquitto/pwfile对应内容
admin:$6$y1gIy8QixvxlVqH2$Jzf+f7A4vTcuKpceVciwi8qL07Q8wkCPGZaFlTqWqHl6Tz4OySA/jNjDHDMiLez3R04s79teDcrFIJBmR4XBgQ==
mosquitto:$6$vc2qZdyCBKl1mroB$tLyPqKO9nshKkYfrj8F7lzzAr60x6n9cx4i2Fuvq1gh8dFCqsoXKNrIxQdKXU/E+YNhK0PG6ffAGeQ1jVVBwbQ==
hthl_bridge:$6$/tsqpcivgBm0mo3r$kaC4xrLLhUYXE6mU28ZymgQ7HEqblY67CN2dn15rnuR7DCYs9w5jeVCuuCIPIW2+kb6ELgflTrLdD2Bhntf9bg==
read 订阅权限 、write 发布权限、# 通配符表示所有的、保存退出。
3:修改 Mosquitto.conf 配置选项
打开mosquitto.conf文件,找到acl_file节点。打开配置做如下修改:
修改前:#acl_file
修改后:acl_file /etc/mosquitto/aclfile.example 根据自己文件实际位置填写
最新文章
- 1.2 - C#语言习惯 - 用运行时常量readonly而不是编译期常量const
- Linux学习之CentOS(二十八)--RAID原理基础及Linux下软件RAID配置
- 【PowerOJ1740】 圆桌问题
- STL or Force --- CSU 1553: Good subsequence
- navicat 连接sqlserver提示要安装 sql server native client
- Bmob用户管理操作
- libyuv 编译for ios
- Java多线程之join
- ADO访问Access数据库错误解决心得随笔
- 委托、匿名函数与Lambda表达式初步
- 在WPF中调用Winform控件
- Apple Remote Push Notifications
- 【转】iOS开发UI篇—iPad和iPhone开发的比较
- Core第三方开源Web框架
- linux下安卓编译apk环境搭建
- 3种日志类型,微信付款反馈-->;写入txt日志
- node.js 抓取
- Make a Person 闭包
- python浅拷贝和深拷贝
- .Net Core实践1
热门文章
- Turn any Linux computer into SOCKS5 proxy in one command
- 类似于GROUP BY SUM() 用于字符串连接的语句
- 2016年终总结--一个Python程序猿的跨界之旅
- Proxmark3命令帮助
- vue刷新当前路由:router-view 复用组件时不刷新的3种解决方案总结
- Android之横屏竖屏显示问题
- html中块注释<;!--[if IE]>;….<;![endif]-->; (<;!--[if !IE]>;||<;![endif]
- bundle中vim相关快捷键的使用
- CSS布局之脱离文档流详解——浮动、绝对定位脱离文档流的区别
- vlc模块间共享变量