MOSQUITTO_PUB(1) Commands MOSQUITTO_PUB(1) (NAME) mosquitto_pub - MQTT .. . (SYNOPSIS) mosquitto_pub [options] -t topic {payload-options} options: [auth-options] [connection-options] [misc-options] [mqtt-options] [output-options] [publish-options] [tls-certificate-options | tls-psk-options] auth-options: [-u username] [-P password] connection-options {[-h hostname] [--unix socket path] [-p port-number] | -L URL} [-A bind-address] [--nodelay] [-S] [--ws] [--proxy socks-url] misc-options: [-o config-file] mqtt-options: [-c] [-D command identifier value] [-i client-id] [-I client-id-prefix] [-k keepalive-time] [-x session-expiry-interval] [-V protocol-version] [--will-topic topic [--will-payload payload] [--will-qos qos] [--will-retain]] output-options: [-d] [--quiet] payload-options: -f file | -l | -m message | -n | -s publish-options: [-q message-QoS] [-r] [--repeat count] [--repeat-delay seconds] tls-certificate-options: [--no-tls] {--cafile file | --capath dir} [--tls-use-os-certs] [--cert file] [--key file] [--ciphers ciphers] [--insecure] [--tls-alpn protocol] [--tls-keylog file] [--tls-version version] [--tls-engine engine] [--keyform {pem | engine}] [--tls-engine-kpass-sha1 kpass-sha1] tls-psk-options: --psk hex-key --psk-identity identity [--ciphers ciphers] [--tls-version version] mosquitto_pub [--help] (DESCRIPTION) mosquitto_pub MQTT .. . (topic) . (ENCRYPTED CONNECTIONS) TLS . . TLS x509 --cafile --capath . -p 8883 --cafile --capath . TLS TLS-PSK --psk --psk-identity . (OPTIONS) mosquitto_pub : . (Default Config File) $XDG_CONFIG_HOME/mosquitto_pub $HOME/.config/mosquitto_pub POSIX %USERPROFILE%\mosquitto_pub . : -option value. . . -S. TLS --no-tls . # . . . (Config File) . . -o config-file . -o . . (The options) -A IP (bind) . . -c, --disable-clean-session << >> (clean session) / (persistent). (broker) (client id) . MQTT -x . QoS 1 QoS 2 . . --id . --cafile (CA) PEM . SSL/TLS . : --capath --capath (CA) PEM . SSL/TLS . --capath <<.crt>> <>> . : --cafile --cert PEM ( ). : --key << >>. --ciphers TLS OpenSSL . ciphers(1) . -d, --debug (debug). -D, --property MQTT . MQTT . : -D command identifier value -D command identifier name value command MQTT CONNECT PUBLISH PUBACK PUBREC PUBCOMP SUBSCRIBE UNSUBSCRIBE DISCONNECT AUTH WILL . . identifier . <<->> : payload-format-indicator. . value . name user-property . value . -f, --file . --help . -h, --host . localhost . -i, --id . MQTT . v3.1.1/v3.1 mosq-XXXXXXXXXXXXXXXXXX X - . v5.0 . -I, --id-prefix (PID) . clientid_prefixes . --id . --insecure . DNS . . . -k, --keepalive PING . . --key PEM TLS . : --cert << >>. --keyform TLS . <> <> . TPM . <> . : --tls-engine. -L, --url URL. : mqtt(s)://[username[:password]@]host[:port]/topic ws(s)://[username[:password]@]host[:port]/path (scheme) : mqtt:// - 1883 mqtts:// - 8883 ws:// - 80 wss:// - 443. -l, --stdin-line (stdin) . -m, --message . -n, --null-message ( ). --nodelay (Nagle) . . . --no-tls . . TLS. TLS . TLS 8883 . -o config-file . . . << >> << >> . -p, --port . MQTT MQTT TLS . -P, --pw . v3.1 v3.1.1 MQTT . --username . --proxy SOCKS5 . <> <> . socks-url socks5h://[username[:password]@]host[:port] . socks5h . %25 %3A %40 % : @ . . . IPv6 socks5h://[::1]:1080. . SOCKS curl(1) . --psk (PSK) ( 0x) TLS-PSK. TLS-PSK --psk-identity . --psk-identity TLS-PSK. . -q, --qos (Quality of Service) . . --quiet . ( --port ). -r, --retain << >> (retain) . mqtt(7) . retain . --repeat -m -f -s ( ) --repeat . : --repeat-delay. --repeat-delay --repeat . --repeat-delay . . . -s, --stdin-file (stdin) . -S SRV DNS . -h _mqtt._tcp. _mqtt._tcp. . -t, --topic (topic) MQTT . MQTT mqtt(7) . --tls-alpn ( MQTT WebSockets). --tls-engine OpenSSL ( ). openssl engine . : --keyform. --tls-engine-kpass-sha1 SHA1 TLS. TLS TPM . SHA1 . : --tls-engine. --tls-keylog file . . TLS file. tcpdump wireshark mqttshark TLS MQTT . Wireshark (Pre)-Master-Secret log filename Transport Layer Security . . --tls-use-os-certs (CA) . --cafile --capath TLS . -L mqtts://... . --tls-version TLS . tlsv1.3 tlsv1.2 . tlsv1.2 . . -u, --username . --pw . --unix (unix domain socket) TCP. -h -L : mosquitto_pub --unix /tmp/mosquitto.sock ... Mosquitto socket_domain mosquitto.conf(5) . -V, --protocol-version MQTT . 5 311 31 mqttv5 mqttv311 mqttv31 . 311 . --will-payload . --will-topic . --will-qos (QoS) (Will). . --will-topic . --will-retain (retained) . --will-topic . --will-topic (topic) . --ws (WebSockets) TCP . -x session-expiry-interval CONNECT. MQTT . 0 4294967294 -1 4294967295 . -c -1 0 . -x -c . (WILLS) . mqtt(7) . --will-topic . (non- retained) QoS 0 . --will-retain --will-payload --will-qos . (PROPERTIES) -D / --property mosquitto_pub . : (Connect) o authentication-data ( - : ) o authentication-method ( UTF-8) o maximum-packet-size ( ) o receive-maximum ( ) o request-problem-information ( ) o request-response-information ( ) o session-expiry-interval ( : -x ) o topic-alias-maximum ( ) o user-property ( UTF-8) (Publish) o content-type ( UTF-8) o correlation-data ( - : ) o message-expiry-interval ( ) o payload-format-indicator ( ) o response-topic ( UTF-8) o topic-alias ( ) o user-property ( UTF-8) (Disconnect) o session-expiry-interval ( ) o user-property ( UTF-8) (Will properties) o content-type ( UTF-8) o correlation-data ( - : ) o message-expiry-interval ( ) o payload-format-indicator ( ) o response-topic ( UTF-8) o user-property ( UTF-8) o will-delay-interval ( ) (EXIT STATUS) . MQTT CONNACK . libmosquitto . CONNACK MQTT v3.1.1: o 0 (Success) o 1 : (Connection refused: Bad protocol version) o 2 : (Connection refused: Identifier rejected) o 3 : (Connection refused: Server unavailable) o 4 : (Connection refused: Bad username/password) o 5 : (Connection refused: Not authorized) CONNACK MQTT v5: o 0 (Success) o 128 (Unspecified error) o 129 (Malformed packet) o 130 (Protocol error) o 131 (Implementation specific error) o 132 (Unsupported protocol version) o 133 (Client ID not valid) o 134 (Bad username or password) o 135 (Not authorized) o 136 (Server unavailable) o 137 (Server busy) o 138 (Banned) o 139 (Server shutting down) o 140 (Bad authentication method) o 141 (Keep alive timeout) o 142 (Session taken over) o 143 (Topic filter invalid) o 144 (Topic name invalid) o 147 (Receive maximum exceeded) o 148 (Topic alias invalid) o 149 (Packet too large) o 148 (Message rate too high) o 151 (Quota exceeded) o 152 (Administrative action) o 153 (Payload format invalid) o 154 (Retain not supported) o 155 (QoS not supported) o 156 (Use another server) o 157 (Server moved) o 158 (Shared subscriptions not supported) o 159 (Connection rate exceeded) o 160 (Maximum connect time) o 161 (Subscription IDs not supported) o 162 (Wildcard subscriptions not supported) : o 27 (Timed out waiting for message) (EXAMPLES) (localhost) QoS 1: o mosquitto_pub -t sensors/temperature -m 32 -q 1 QoS 0: o mosquitto_pub -h 192.168.1.1 -p 1885 -t sensors/temperature -m "1266193804 32" . (retained) : o mosquitto_pub -r -t switches/kitchen_lights/status -m "on" : o mosquitto_pub -t my/topic -f ./data o mosquitto_pub -t my/topic -s < ./data Current Cost (stdin) : o read_cc128.pl | mosquitto_pub -t sensors/cc128 -l zigbee2mqtt : o mosquitto_pub -t zigbee2mqtt/power-microwave/set -m '{"state":"ON"}' (FILES) $XDG_CONFIG_HOME/mosquitto_pub, $HOME/.config/mosquitto_pub, $HOME/snap/mosquitto/current/.config/mosquitto_pub ( snap) . (BUGS) mosquitto : https://github.com/eclipse- mosquitto/mosquitto/issues (SEE ALSO) mosquitto(7), mqtt(7), mosquitto_rr(1), mosquitto_sub(1), mosquitto(8), libmosquitto(3), mosquitto-tls(7) (AUTHOR) Roger Light Mosquitto Project 04/03/2026 MOSQUITTO_PUB(1)