zoukankan      html  css  js  c++  java
  • Mosquitto 创建用户自动输入密码

    1,Mosquitto默认是匿名用户登录,修改成用户登录模式需要修改文件/etc/mosquitto/mosquitto.conf

          添加如下:      

          allow_anonymous false
          password_file /etc/mosquitto/pwfile  //可以指定自己的文件

    2, 添加用户

          mosquitto_passwd -c /etc/mosquitto/pwfile xtest   //添加用户xtest  ,存在有其他用户的情况下,不用-c ,-c 会把其他用户的信息清除掉。

          

    3,查看

          cat /etc/mosquitto/pwfile

          

          生成了用户xtest

    4,我的项目中需要在django中自动生成用户。如何解决2中描述的手动输入密码的方式。

          python 中提供了一个pexcept 工具可以解决这个问题。pip install pexcept 完成安装。

          实现代码如下:      

    import pexpect
    sub = pexpect.spawn('mosquitto_passwd /etc/mosquitto/pwfile %s'%‘testtest’)
    sub.expect('Password:')//模拟第一次密码输入
    sub.sendline('12345678')
    sub.expect('Reenter password:')//模拟第二次密码输入
    sub.sendline('12345678')

    sub.interact()
  • 相关阅读:
    HL 7.19 FFT多项式乘法
    HL 7.18 杂题整理 随笔
    BZOj 3208 食物 生成函数+广义二项式定理
    HL 7.14 整理杂题 随笔
    AC自动机 后缀数组 随笔
    Python 之time时间模块
    Python 之sys系统模块
    Uni-app 之猿产地项目
    Tkinter 之socket聊天室
    Python 之logging日志模块
  • 原文地址:https://www.cnblogs.com/huanhuaqingfeng/p/11283191.html
Copyright © 2011-2022 走看看