10
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Mosquitto で Username と Password を使う

Posted at

次のページを参考にしました。
Mosquitto Username and Password Authentication -Configuration and Testing

  1. password.txt というファイルを作成します。
password.txt
steve:password
jim:topsecret
  1. このファイルを暗号化します。
mosquitto_passwd -U password.txt

次のようなファイルに変換されます。

password.txt
steve:$6$4lRl06+qx3nS+0Gx$SZUEnAv/2u+RhIHJV7lM4NHh7R8AZcrtW1lqdqJ77N36meVnya+lvkX++/S1J+JzBrGWiLG5B20e8tfk1hM9oQ==
jim:$6$JtT1tjFAMAaxMQCt$hZc7Uuaa8UAwC61p/oy3JUAe0kExDskehtKwD6YRUezOajYHT7ZQcpX+1g3ofjsDBqs4LpSaHr3e9rAXc5pG+A==
  1. 変換されたファイルを /etc/mosquitto/ にコピーします。

  2. /etc/mosquitto/mosquitto.conf を編集します。

#allow_anonymous true
allow_anonymous false
password_file /etc/mosquitto/password.txt
  1. mosquitto を再起動します。
sudo systemctl restart mosquitto

次は、ローカルでサーバーを動かしている時の接続例です。

サブスクライブ

mosquitto_sub -d -t orz \
        -u jim -P topsecret \
        --topic sensors/topic_1

パブリッシュ

mosquitto_pub -d -t orz -m "こんにちは Feb/09/2018 PM 13:47" \
        -u jim -P topsecret \
        --topic sensors/topic_1
10
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?