# What is the mqtt-cli command to publish and subscribe with credentials

**URL:** <https://community.hivemq.com/t/what-is-the-mqtt-cli-command-to-publish-and-subscribe-with-credentials/2385>\
**Category:** Uncategorized\
**Created:** [September 25, 2023, 2:34pm UTC](https://community.hivemq.com/t/what-is-the-mqtt-cli-command-to-publish-and-subscribe-with-credentials/2385 "2023-09-25T14:34:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Susan](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@Susan](https://community.hivemq.com/u/Susan)\
**Post date:** [September 25, 2023, 2:34pm UTC](https://community.hivemq.com/t/what-is-the-mqtt-cli-command-to-publish-and-subscribe-with-credentials/2385/1 "2023-09-25T14:34:17Z")

</div>

I enabled Hive ESE so I need to provide user name and password during sub and pub.  
I was using

docker run hivemq/mqtt-cli sub -t /topic/subtopic/mytopic -h xx.xx.xx.xx  
docker run hivemq/mqtt-clipub -t /topic/subtopic/mytopic -m Hello! -h xx.xx.xx.xx

Can you give me the similar command as above but with the user name and password arguments?

Thank you!

---

<div class="post-metadata">

**Author:** ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://community.hivemq.com/u/Diego)\
**Post date:** [September 25, 2023, 2:54pm UTC](https://community.hivemq.com/t/what-is-the-mqtt-cli-command-to-publish-and-subscribe-with-credentials/2385/2 "2023-09-25T14:54:36Z")

</div>

Hello @Susan

You can use something like the sample below. To display all MQTT CLI parameters please use `--help` parameter.

```auto
docker run hivemq/mqtt-cli sub -t /topic/subtopic/mytopic -h xx.xx.xx.xx -u TYPE_YOUR_USERNAME -pw TYPE_YOUR_PASSWORD

docker run hivemq/mqtt-cli pub -t /topic/subtopic/mytopic -m Hello! -h xx.xx.xx.xx -u TYPE_YOUR_USERNAME -pw TYPE_YOUR_PASSWORD

```

Kind regards,  
Diego from HiveMQ Team

---

<div class="post-metadata">

**Author:** ![Susan](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@Susan](https://community.hivemq.com/u/Susan)\
**Post date:** [September 25, 2023, 7:01pm UTC](https://community.hivemq.com/t/what-is-the-mqtt-cli-command-to-publish-and-subscribe-with-credentials/2385/3 "2023-09-25T19:01:07Z")

</div>

Thank you what if I want to subscribe to all topic? Is the following correct? or I need to quote # or I still need a /topic/#?  
docker run hivemq/mqtt-cli sub -t # -h xx.xx.xx.xx -u TYPE\_YOUR\_USERNAME -pw TYPE\_YOUR\_PASSWORD

---

<div class="post-metadata">

**Author:** ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://community.hivemq.com/u/Diego)\
**Post date:** [September 26, 2023, 10:19am UTC](https://community.hivemq.com/t/what-is-the-mqtt-cli-command-to-publish-and-subscribe-with-credentials/2385/4 "2023-09-26T10:19:34Z")

</div>

Hello @Susan

It’s correct! If you’re looking to dive into the topic and understand it better, a great starting point would be our “MQTT Essentials” series. It provides comprehensive insights into MQTT and can help lay a strong foundation for you.

> **[MQTT Essentials - All Core Concepts Explained](https://www.hivemq.com/mqtt/)**
>
> MQTT Essentials: Learn the core concepts of MQTT, its features and other essential information about the protocol for IoT and IIoT.

Kind regards,  
Diego from HiveMQ Team
