Blog

Reach an MQTT Broker Behind an SSH Server from Your iPhone

Connect your iPhone to a Mosquitto broker that listens only on 127.0.0.1 behind an SSH server. Set up the tunnel, check the host key, and read the Doctor result.

November 5, 2026

The Broker You Cannot Reach Directly

A common setup looks like this: a Mosquitto broker runs on a small server at home or in a data center, and its config binds the listener to the loopback address only.

# /etc/mosquitto/conf.d/local.conf
listener 1883 127.0.0.1
allow_anonymous false
password_file /etc/mosquitto/passwd

Nothing outside that machine can open port 1883, which is the point. The only way in is SSH. On a laptop you reach the broker with a forwarded port:

ssh -L 1883:127.0.0.1:1883 pi@home.example.com

and point any MQTT client at localhost:1883. On a phone there is no terminal to keep that session open. MQTT Commander 1.4.0 does the forwarding itself: it opens the SSH connection, asks the server for a channel to the broker, and runs the MQTT connection through that channel. If the broker also uses TLS, the existing TLS and mTLS settings keep working on top of the tunnel.

The same approach covers brokers that listen on a private network the SSH server can see but your phone cannot.


Add the SSH Server

An SSH server is its own entry in the app, like a certificate in the Certificate Manager. Open Settings, tap SSH servers, then Add SSH server, and fill in the host, port and username. You save it once and reuse it across broker profiles.

Pick one sign-in method:

  • Password. The app stores it in the iOS Keychain.
  • Private key. Import an OpenSSH private key from Files. If the key has a passphrase, enter it and tap Read key.
  • Device key. The app creates a key in the Secure Enclave. It shows a public key line, and you append that line to ~/.ssh/authorized_keys for the user you sign in as on the server. The private key stays on the device, and you can require Face ID or Touch ID to use it.
  • Server questions (2FA). If the server asks for a code, the app shows the server’s questions on a separate screen.

Point a Broker Profile at the Server

Create a broker profile as usual, then turn on Connect through SSH and choose the server you saved.

The broker address is read from the SSH server’s side, so for the Mosquitto example above you enter 127.0.0.1 (or localhost) and port 1883. Here localhost means the SSH server itself, not your phone. If the broker lives on another machine in the server’s network, enter that machine’s address.

Tap Save and run Doctor. Connection Doctor runs the SSH steps first, then TLS and MQTT, and shows each result.


Why the Host Key Fingerprint Matters

The first time the app connects to a server, it has no way to know the server is the one you meant. SSH answers this with the host key: a key the server presents when the connection opens. The app shows its fingerprint in full, with the command to read the same fingerprint on the server:

ssh-keygen -lf /etc/ssh/ssh_host_*_key.pub

Run it on the server, compare the output with the screen, and tap Trust and connect only if they match. If you trust a key that belongs to someone else, for example on a shared Wi-Fi network where another device answers in place of your server, that device can read everything you send through the tunnel, including your MQTT credentials, and with password sign-in it also receives your SSH password.

After you trust a key, the app remembers it. If the server sends a different key later, the app stops before it sends your password or key. A reinstalled server has a new key, and so does someone sitting between you and the server, so the screen asks you to compare both fingerprints with the server administrator before you accept the new one. Each server’s card in SSH servers lists its trusted keys and a Forget button.


When the Connection Fails

Connection Doctor names the step that broke instead of reporting a generic failure:

  • SSH server. The server did not answer. Check the address, the port and the network access from your phone, or the server’s SSH settings if the handshake fails.
  • Host key. The key is unknown and waits for your decision, or it changed and the app stopped.
  • Sign-in. The server rejected the password, rejected the key, or rejected the second factor, or the key passphrase is wrong. The message tells you which one.
  • Tunnel. The server denied port forwarding, cannot reach the broker address, or the tunnel closed. If AllowTcpForwarding is set to no in the server’s sshd_config, the tunnel cannot open until an administrator allows it.

When the SSH steps pass but MQTT fails, you are back in familiar territory: the failing stage is TLS, the certificate or the MQTT CONNACK, and the TLS and mTLS debugging guide applies unchanged.


What Is Free and What Needs Pro

Adding an SSH server and running Connection Doctor through the SSH steps, TLS and MQTT is free. A live session through SSH, meaning topics, log, publish and Live Board, comes with the one-time Pro unlock. If you bought the paid app before it went free, you keep Pro at no cost.

Saved commands in Siri and Shortcuts, and session restore at launch, work through SSH when the server asks for no code and the device key needs no Face ID. In other cases the command asks you to open the app, and at launch you tap Connect.


Where Your Secrets Live

The app talks to your SSH server directly. MQTT Commander runs no relay server in between, and we do not see the traffic. SSH passwords and imported keys are stored in the iOS Keychain, and a key created on the device lives in the Secure Enclave. Export and import carry SSH servers without passwords or keys, so you set up secrets again on a new device.

Read more on the SSH tunnels feature page, or start from getting started with MQTT on iPhone. MQTT Commander is free to download for iOS 17 and iPadOS 17 and later, with no subscription and an optional $4.99 one-time Pro unlock. SSH tunnels need version 1.4.0 or later.

← All guides

Debug MQTT on your iPhone

MQTT Commander brings this workflow to iOS and iPadOS.

Free · Pro unlock $4.99, one-time