MQTT之mosquitto_passwd命令使用

可以使用mosquitto自带的mosquitto_passwd命令生成密码文件。

      mosquitto_passwd -c [最终生成的password_file文件]  [用户名] 。

      #: mosquitto_passwd -c passwd.conf  jinhe_sub 

      输入命令后,控制台会提示输入新建用户的密码,连续输入两次密码后,则会生成一个passwd.conf文件。

     注意,mosquitto_passwd -c命令每次都只会生成只包含一个用户的文件,如果你想在passwd.conf中存放多个用户, 可以使用mosquitto_passwd -b 命令。

    mosquitto_passwd -b [最终生成的password_file文件]  [用户名]  [密码]。

    mosquitto_passwd -b命令必须在控制台输入明文的密码,且每次只是在passwd.conf中新增一个用户,不会覆盖之前已生成的用户。

   同时也可以使用mosquitto_passwd -D命令删除一个用户。


更具体如下:

Name

mosquitto_passwd — manage password files for mosquitto

Synopsis

mosquitto_passwd [ -c | -D ] passwordfile username

mosquitto_passwd -b passwordfile username password

mosquitto_passwd -U passwordfile

Description

mosquitto_passwd is a tool for managing password files the mosquitto MQTT broker.

Usernames must not contain ":". Passwords are stored in a similar format to crypt(3).

Options

-b

Run in batch mode. This allows the password to be provided at the command line which can be convenient but should be used with care because the password will be visible on the command line and in command history.

-c

Create a new password file. If the file already exists, it will be overwritten.

-D

Delete the specified user from the password file.

-U

This option can be used to upgrade/convert a password file with plain text passwords into one using hashed passwords. It will modify the specified file. It does not detect whether passwords are already hashed, so using it on a password file that already contains hashed passwords will generate new hashes based on the old hashes and render the password file unusable.

passwordfile

The password file to modify.

username

The username to add/update/delete.

password

The password to use when in batch mode.

Examples

Add a user to a new password file:

  • mosquitto_passwd -c /etc/mosquitto/passwd ral

Delete a user from a password file

  • mosquitto_passwd -D /etc/mosquitto/passwd ral

Bugs

mosquitto bug information can be found at https://github.com/eclipse/mosquitto/issues

See Also

mosquitto(8) , mosquitto.conf(5) , mqtt(7)

Author

Roger Light 


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
设备端与阿里云IoT平台建立MQTT通道的CONNECT报文有三个关键参数:客户端标识符 (ClientId) ,用户名(User Name),密码(Password)。这三个参数由设备三元组(productKey,deviceName,deviceSecret)按照阿里云IoT签名规则生成。 参数 生成方式 描述 username deviceName+"&"+productKey password sign_hmac(deviceSecret,content) sign_hmac为mqttClientId中的signmethod content为 "clientId${id}deviceName${deviceName}productKey${productKey}timestamp${timestamp}" 其中 id:表示客户端ID,64字符内。 timestamp:表示当前时间毫秒值。 clientId id+"|securemode=3,signmethod=hmacsha1,timestamp="+timestamp+"|" id:表示客户端ID,64字符内。 timestamp:表示当前时间毫秒值。 securemode:表示安全模式:可选值有2(TLS加密)和3(非加密) signmethod:表示签名算法类型。支持hmacmd5,hmacsha1和hmacsha256 2. 三元组接入示例 2.1 设备三元组信息 设备三元组 productKey = a14Xib5kdYd deviceName = light1983432 deviceSecret = oLyaKqVxtRvjH284LdhqVgVUx1UPy6zq 建立MQTT连接时参数 clientId = SN1928339 timestamp = 1539421321846 signmethod = hmacsha1 2.2 参数生成结果 mqttClientId = SN1928339|securemode=3,signmethod=hmacsha1,timestamp=1539421321846| mqttUsername = light1983432&a14Xib5kdYd mqttPassword = b2488041f64f425016b467ee1c94959ebd592ad1 生成password的content content=clientIdSN1928339deviceNamelight1983432productKeya14Xib5kdYdtimestamp1539421321846 2.3 建立连接 mqttClientId作为MQTT客户端标识符 (ClientId) mqttUsername作为MQTT用户名(User Name) mqttPassword作为MQTT密码(Password) 在线Password生成算法验证
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值