emqttd设置密码认证
安装省略
1、配置配置文件
[root@localhost ~]# cd /usr/local/emqttd/bin/
[root@localhost bin]# vim ../etc/emq.conf
mqtt.allow_anonymous = false 关闭匿名
2、重启emqttd
[root@localhost bin]#./emqttd stop
[root@localhost bin]#./emqttd start
3、加载认证模块
./emqttd_ctl plugins load emq_auth_username
4、设置用户密码认证
语法:
[root@localhost bin]# ./emqttd_ctl admins --help
admins add <Username> <Password> <Tags> # Add dashboard user
admins passwd <Username> <Password> # Reset dashboard user password
admins del <Username> # Delete dashboard user
[root@localhost bin]#
[root@localhost bin]# ./emqttd_ctl users --ehlp
users list # List users
users add <Username> <Password> # Add User
users del <Username> # Delete User
例如:
[root@localhost bin]# ./emqttd_ctl users list
admin
[root@localhost bin]# ./emqttd_ctl users del admin
ok
[root@localhost bin]# ./emqttd_ctl users add sdsfdsfdsf FINxxAImVVNbCqzezCGkdvVViAIaaHhl
ok
[root@localhost bin]#
[root@localhost bin]# ./emqttd_ctl users list
otoyix
注:为防止密码忘记,可以在配置文件中记录一下
[root@localhost bin]# vim ../etc/plugins/emq_auth_username.conf
##--------------------------------------------------------------------
## Username Authentication Plugin
##--------------------------------------------------------------------
## Examples:
##auth.user.1.username = sdsfdsfdsf
##auth.user.1.password = FINxxAImVVNbCqzezCGkdvVViAIaaHhl
或
cat /usr/local/emqttd/etc/emq.conf |grep allow_anonymous 关闭匿名用户
mqtt.allow_anonymous = false
cat emqttd/etc/plugins/emq_auth_username.conf 设置用户名密码
##--------------------------------------------------------------------
## Username Authentication Plugin
##--------------------------------------------------------------------
## Examples:
auth.user.1.username = admin
auth.user.1.password = public
auth.user.2.username = feng@emqtt.io
auth.user.2.password = public
auth.user.3.username = name~!@#$%^&*()_+
auth.user.3.password = pwsswd~!@#$%^&*()_+
cd /usr/local/emqttd/bin/
./emqttd_ctl plugins load emq_auth_username 加载密码认证
./emqttd_ctl users list 查看用户信息
name~!@#$%^&*()_+
admin
feng@emqtt.io
-------------------------end