本文将讲解 Mosquitto 用户机制、如果还没有搭建 Mosquitto 服务的可以参考我的另外两篇文章<< 一、Mosquitto 介绍&安装>> << 二、 Mosquitto 的使用说明 >> 来搭建 Mosquitto 服务。  

  mosquitto中可以添加多个用户,只有使用用户名和密码登陆服务器才允许用户进行订阅与发布操作。可以说用户机制是mosquitto重要的安全机制,增强服务器的安全性。
用户与权限配置需要修改3处地方: 

  1、mosquitto中最最最重要的配置文件mosquitto.conf(配置文件的位置请看<< 一、Mosquitto 介绍&安装>> 文章中 1.5节 默认安装配置文件位置 中会有说明 )。
  2、pwfile.example (保存用户名与密码)
  3、aclfile.example (保存权限配置)

  首先我们来新增两个用户 1: admin/admin 2: mosquitto/mosquitto 具体步骤:

  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 服务都需要输入用户名密码、测试请用上篇文章<<三、Mosquitto Java 客户端实现>> 中测试代码测试。

# 服务进程的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

1524729248: New connection from 192.168.72.103 on port 1883.
1524729248: New client connected from 192.168.72.103 as mosqsub|2205-centoshost (c1, k60, u'mosquitto').
1524729286: New connection from 192.168.72.103 on port 1883.
1524729286: New client connected from 192.168.72.103 as mosqpub|2207-centoshost (c1, k60, u'admin').
1524729286: Client mosqpub|2207-centoshost disconnected.
1524729494: New connection from 192.168.72.1 on port 1883.
1524729494: New client connected from 192.168.72.1 as client11 (c1, k20, u'admin').
1524729506: New connection from 192.168.72.1 on port 1883.
1524729506: New client connected from 192.168.72.1 as server11 (c0, k20, u'mosquitto').
1524729521: New connection from 192.168.72.1 on port 1883.
1524729522: Client server11 already connected, closing old connection.
1524729522: Client server11 disconnected.
1524729522: New client connected from 192.168.72.1 as server11 (c0, k20, u'mosquitto').
1524729549: New connection from 192.168.72.1 on port 1883.
1524729549: Client client11 already connected, closing old connection.
1524729549: Client client11 disconnected.
1524729549: New client connected from 192.168.72.1 as client11 (c1, k20, u'admin').
1524729560: New connection from 192.168.72.1 on port 1883.
1524729560: Client server11 already connected, closing old connection.
1524729560: Client server11 disconnected.
1524729560: New client connected from 192.168.72.1 as server11 (c0, k20, u'mosquitto').
1524729569: New connection from 192.168.72.1 on port 1883.
1524729569: Client server11 already connected, closing old connection.
1524729569: Client server11 disconnected.
1524729569: New client connected from 192.168.72.1 as server11 (c0, k20, u'mosquitto').
1524729599: New connection from 192.168.72.1 on port 1883.
1524729599: Client server11 already connected, closing old connection.
1524729599: Client server11 disconnected.
1524729599: New client connected from 192.168.72.1 as server11 (c0, k20, u'mosquitto').
1524729680: Socket error on client server11, disconnecting.
1524729704: New connection from 192.168.72.1 on port 1883.
1524729704: Socket error on client <unknown>, disconnecting.
1524729704: New connection from 192.168.72.1 on port 1883.
1524729704: Socket error on client <unknown>, disconnecting.
1524729737: Socket error on client client11, disconnecting.
^C1524729745: mosquitto version 1.4.14 terminating
[wangshumin@centoshostnameKL3 mosquitto]$ su root
密码:
[root@centoshostnameKL3 mosquitto]# ll
总用量 100
-rw-r--r--. 1 root root   280 4月  25 17:07 aclfile
-rw-r--r--. 1 root root   230 4月  25 16:46 aclfile.example
-rw-r--r--. 1 root root 38064 4月  26 15:51 mosquitto.conf
-rw-r--r--. 1 root root 37730 4月  25 16:46 mosquitto.conf.example
-rw-r--r--. 1 root root    23 4月  25 16:46 pskfile.example
-rw-r--r--. 1 root root   234 4月  26 15:52 pwfile
-rw-r--r--. 1 root root   355 4月  25 16:46 pwfile.example
[root@centoshostnameKL3 mosquitto]# cat pwfile
admin:$6$y1gIy8QixvxlVqH2$Jzf+f7A4vTcuKpceVciwi8qL07Q8wkCPGZaFlTqWqHl6Tz4OySA/jNjDHDMiLez3R04s79teDcrFIJBmR4XBgQ==
mosquitto:$6$vc2qZdyCBKl1mroB$tLyPqKO9nshKkYfrj8F7lzzAr60x6n9cx4i2Fuvq1gh8dFCqsoXKNrIxQdKXU/E+YNhK0PG6ffAGeQ1jVVBwbQ==
[root@centoshostnameKL3 mosquitto]# vim mosquitto.conf
[root@centoshostnameKL3 mosquitto]# vim mosquitto.conf

[wangshumin@centoshostnameKL3 ~]$ mosquitto_pub -t mqtt -h centoshostnameKL3 -m "new locatio"  -u admin -P 123456

[wangshumin@centoshostnameKL3 ~]$

[wangshumin@centoshostnameKL3 ~]$ mosquitto_sub -t mqtt -h centoshostnameKL3
new locatio
new locatio
new locatio
new locatio
new locatio
new locatio
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
^C
[wangshumin@centoshostnameKL3 ~]$ mosquitto_sub -t mqtt -h centoshostnameKL3 -u mosquitto -P 123456
new locatio
^C

四、Mosquitto 高级应用之用户配置相关推荐

  1. mosquitto --用户配置 及权限管理

    mosquitto中能够添加多个用户,只有使用用户名和密码登录服务器才容许用户进行订阅与发布操做.能够说用户机制是mosquitto重要的安全机制,加强服务器的安全性. 用户与权限配置须要修改3处地方 ...

  2. 【AD用户配置系列三】文件夹重定向为用户登录与注销加速

    在前面两篇文章中(让IT省心省力的漫游配置文件和批量修改漫游配置文件路径),跟大家介绍了漫游配置文件在企业IT基础环境管理中的使用方法.通过漫游配置文件实现了用户配置文件的集中管理:这对企业IT部门来 ...

  3. RabbitMQ 高级指南:从配置、使用到高可用集群搭建

    博主说:在项目中,通过 RabbitMQ,咱们可以将一些无需即时返回且耗时的操作提取出来,进行异步处理,而这种异步处理的方式大大的节省了服务器的请求响应时间,从而提高了系统的吞吐量. 正文 1 Rab ...

  4. 一个完整的Installshield安装程序实例—艾泽拉斯之海洋女神出品(四) --高级设置二...

    一个完整的Installshield安装程序实例-艾泽拉斯之海洋女神出品(四) --高级设置二 原文:一个完整的Installshield安装程序实例-艾泽拉斯之海洋女神出品(四) --高级设置二 上 ...

  5. oracle高级复制同步复制配置步骤

    ***业务需要,先做个高级复制的(同步复制).详细的说明如下:*** [Oracle] oracle高级复制同步复制配置步骤 首先,数据库要具备高级复制功能(用system身份登录数据库,查看v$op ...

  6. Oracle 高级复制 (同步复制) 配置步骤详细说明

    ***业务需要,先做个高级复制的(同步复制).详细的说明如下:*** [Oracle] oracle高级复制同步复制配置步骤 首先,数据库要具备高级复制功能(用system身份登录数据库,查看v$op ...

  7. ESXi6.5环境搭建(四:虚拟机操作系统安装及配置)

    实验目的及要求 完成VMware workstations安装,会应用相关操作: 完成虚拟机中ESXI6.5平台的安装及网络环境配置: 完成VMware vSphere Client 6.0软件在PC ...

  8. 关于非root用户配置ssh运行环境

    第一步,我们创建Linux用户: 用root用户登录 A.增加用户组命令:groupadd –g 500 hadoop           //此处500是手动设置groupID Linux保留前50 ...

  9. Vsftpd 虚拟用户配置参考---终极版

    Vsftpd 虚拟用户配置文档 一.主要文件列表 虚拟用户列表 account.txt 口令库文件 /etc/vsfptd/account.db PAM认证 /etc/pam.d/vs_1 主配置文件 ...

  10. Excel催化剂开源第10波-VSTO开发之用户配置数据与工作薄文件一同存储

    在传统的VBA开发中,若是用的是普通加载项方法,是可以存储数据在xlam上的,若用的是Com加载项方法同时是Addins程序级别的项目开发的,配置文件没法保存到工作薄中,一般另外用配置文件来存放供调用 ...

最新文章

  1. 阿里云DDoS高防 - 访问与攻击日志实时分析(二)
  2. 你必须会的启发式搜索算法--A*算法
  3. java模拟国际象棋游戏_java国际象棋小游戏
  4. 107. Leetcode 123. 买卖股票的最佳时机 III (动态规划-股票交易)
  5. SpringBoot中对thymeleaf的时间进行格式化显示
  6. linux上常用工具集
  7. hdu 4982 贪心构造序列
  8. jvm在不同系统中的最大内存空间地址
  9. 利用python进行数据分析论文_利用Python进行数据分析之pandas的高级用法
  10. 自己动手写spring(三) 支持注解方式
  11. 算法题存档20190206
  12. HDU 5970 CCPC2016合肥 求等差数列整除整数下取整求和
  13. label怎么换行 vb_ASP.NET Lable中进行换行解决方案
  14. 《领导力与沟通艺术》
  15. 潘多拉路由器搭建php,MT7620A 无线路由 极路由 1S 定制版 OPERWRT 潘多拉 中继 营销...
  16. java partial class_easymock教程-partial class mocking
  17. 树莓派1——摄像头实时视频和截图
  18. java费切罗_细数目前主流的十二个自行车种类
  19. inno setup 自定义生成的卸载程序
  20. 惊了,Python 民俗社会科学项目,看看能否预测【面向哪里写BUG少】

热门文章

  1. client中周期性边界_周期性边界条件
  2. 天使轮,种子,A轮,B轮,C轮,Pre-IPO
  3. 解决图片闪烁问题(雪碧图)
  4. Manjaro学习笔记
  5. 环信服务器发送消息,环信服务器发送消息
  6. c语言 double **x,C语言题目 若已定义x和y为double类型,则表达式“x=1,y=x+3/2的值是:...
  7. 正睿OI补题(贪心)
  8. 如何创建 Ubuntu 信息亭(kiosk)
  9. [精彩泄漏截图] 2006最值得期待的游戏
  10. 【哈利波特】Sherbert Lemon对HP的解读之10