Mosquitto: Difference between revisions

imported>Onny
mNo edit summary
imported>Onny
m Fix password authentication example
Line 27: Line 27:
=== Password authentication ===
=== Password authentication ===


The following command will generate a hashed representation for the password <code>mypasswd</code>.
The following command will generate a hashed password for the user <code>root</code> into the file <code>/tmp/passwd</code>.


<syntaxHighlight lang="bash">
<syntaxHighlight lang="bash">
echo mypasswd | mkpasswd -m sha-512 -s | sed 's/$/==/'
nix shell nixpkgs#mosquitto --command mosquitto_passwd -c /tmp/passwd root
cat /tmp/passwd
# root:$7$101$KIGAc4K4Pj2zfump$a1s19bL++vN7RlUqJne869JZepEditIOTDPrmaRG2Jlg37/uNJcLzxjk6n5adwbc7COd3eyXuJ7T+CEI+wwxvQ==
</syntaxHighlight>
</syntaxHighlight>


Change the Mosquitto listeners configuration by addming a user, in this example called <code>root</code> with the hased password from the command above.
Use the hash after <code>root:</code> for the following configuration.
 
Change the Mosquitto listeners configuration by addming a user, in this example called <code>root</code> with the hased password.


<syntaxHighlight lang="nix">
<syntaxHighlight lang="nix">
Line 53: Line 57:
== Usage ==
== Usage ==


Testing the server is possible by running a listening comand
Testing the server is possible by running a listening comand. We also supply username <code>root</code> and password <code>mypasswd</code> from above.


<syntaxHighlight lang="bash">
<syntaxHighlight lang="bash">
nix shell nixpkgs#mosquitto --command mosquitto_sub -h localhost -t test
nix shell nixpkgs#mosquitto --command mosquitto_sub -h localhost -t test -u root -p mypasswd
</syntaxHighlight>
</syntaxHighlight>


Line 62: Line 66:


<syntaxHighlight lang="bash">
<syntaxHighlight lang="bash">
nix shell nixpkgs#mosquitto --command mosquitto_pub -h localhost -t test -m "Hello"
nix shell nixpkgs#mosquitto --command mosquitto_pub -h localhost -t test -m "Hello" -u root -p mypasswd
</syntaxHighlight>
</syntaxHighlight>


[[Category:Applications]]
[[Category:Applications]]