$linuxjunkies
>

mqtt-cli(1)

A command-line interface for interacting with MQTT brokers, allowing publish/subscribe operations and broker management.

UbuntuDebianFedoraArch

Synopsis

mqtt-cli [OPTION]... COMMAND [ARGS]...

Description

mqtt-cli is a versatile command-line tool for working with MQTT message brokers. It supports both MQTT 3.1.1 and MQTT 5.0 protocols, enabling users to publish messages, subscribe to topics, inspect broker information, and manage client connections without writing code.

Common operations include connecting to a broker, publishing test messages to verify connectivity, subscribing to topics for monitoring, and debugging MQTT-based systems. It supports secure connections via TLS/SSL and authentication with username/password or client certificates.

Common options

FlagWhat it does
-h, --helpShow help message and exit
-v, --versionDisplay version information
-b, --brokerSpecify broker address (e.g., tcp://localhost:1883)
-u, --usernameSet username for broker authentication
-pw, --passwordSet password for broker authentication
--cafilePath to CA certificate file for TLS verification
--certPath to client certificate file for mutual TLS
--keyPath to client private key file for mutual TLS
-i, --identifierSet MQTT client identifier/ID
-q, --qosSet Quality of Service level (0, 1, or 2)
-r, --retainedPublish message as retained
-t, --topicSpecify MQTT topic

Examples

Publish a temperature reading to a topic on the specified broker

mqtt-cli pub -b tcp://broker.example.com:1883 -t 'home/temperature' -m '22.5'

Subscribe to all sensor data using wildcard pattern, displaying received messages

mqtt-cli sub -b tcp://localhost:1883 -t 'sensors/+/data'

Publish a message using broker credentials for authentication

mqtt-cli pub -b tcp://localhost:1883 -u user -pw password -t 'test' -m 'Hello MQTT'

Subscribe to alerts over secure TLS connection with CA certificate verification

mqtt-cli sub -b mqtts://broker.example.com:8883 -t 'alerts/#' --cafile /etc/ssl/certs/ca.pem

Publish a retained message so new subscribers immediately receive the current value

mqtt-cli pub -b tcp://localhost:1883 -t 'config/mode' -m 'auto' -r

Subscribe to system topic showing connected clients with QoS 1

mqtt-cli sub -b tcp://localhost:1883 -t '$SYS/broker/clients/+' -q 1

Related commands