pub - Man Page

publishes a message to an MQTT topic


pub [Options]


pub connects to the given MQTT broker and publishes stdin to the specified topic.

All options can be passed either as command-line arguments or can be specified in a simple config file.


-broker URL

broker address (should be in the form of a URL)

-ca-root FILE

path to a FILE containing CA certificates (optional)

-cert-file FILE

authenticate with a certificate


discard any pending messages from the broker (default true)

-client-id STRING

unique identifier for this client (defaults to a semi-random string)

-config FILE

path to FILE containing configuration values (optional)

-header KEY=VALUE

set an HTTP header (in KEY=VALUE form) (can be specified multiple times)

-key-file FILE

authenticate with a private key

-password STRING

authenticate with a password


quality of service for messages


retain message on the broker

-topic STRING

topic to publish or subscribe to (can be specified multiple times)

-username STRING

authenticate with a username


increase output


Any option may be specified as a value in a configuration file instead of (or in addition to) a command-line option. Values present on the command-line take precedent over values in the configration file. Thus it is easy to create a base configration file that can be augmented easily at run time.

The configuration file takes the form of a simple space-separated "option value" format (i.e. "broker tcp://").


Publish a message to a topic anonymously.

echo "hello" | pub -broker tcp:// -topic mqttcli/pubtest


Link Dupont <>