moshterm

~ tunnel

SSH through a Cloudflare Tunnel

moshterm connects to SSH hosts published through a Cloudflare Tunnel from iPhone, iPad and Android, with no cloudflared on the phone: enter the tunnel's public hostname as the host. It can also keep the tunnel as a backup that is used only when the direct address can't be reached. Mosh needs UDP, so tunnel sessions run over SSH.

App Store coming soon Get it on Google Play

Free, no account. moshterm Pro adds live previews.

Publish SSH from the host

On the computer, with cloudflared installed and signed in to your Cloudflare account (cloudflared tunnel login):

# oncecloudflared tunnel create studio
# the hostname you will type in the appcloudflared tunnel route dns studio ssh.example.com
# ~/.cloudflared/config.yml · point the hostname at sshdtunnel: <tunnel-id> credentials-file: /home/you/.cloudflared/<tunnel-id>.json ingress: - hostname: ssh.example.com service: ssh://localhost:22 - service: http_status:404
# or install it as a servicecloudflared tunnel run studio

One sshd setting for OpenSSH 9.8 and later

Every connection through the tunnel reaches sshd from cloudflared on the same machine, so to sshd they all come from one address. OpenSSH 9.8 and later penalize an address after repeated failed or dropped connections, and once that happens every new connection through the tunnel is refused, while the session you already have keeps working. Exempt the loopback addresses:

# /etc/ssh/sshd_config · add this linePerSourcePenaltyExemptList 127.0.0.1,::1
# Debian and Ubuntusudo systemctl reload ssh

Cloudflare Access

If the hostname is behind Cloudflare Access, the app opens the sign-in page in the browser when Access asks for it. For a hostname protected by a service token, enter the token's client ID and secret in the host's settings.

Backup route, jump hosts and keys

  • Keep the host's normal address and add the tunnel hostname as a backup. The tunnel is used only when the direct address can't be reached, for example away from home.
  • Connect through another saved host first, as a jump host. SSH agent forwarding is a per-host switch.
  • On iPhone and iPad, an SSH key can live on a YubiKey (PIV).
  • Host keys are trusted on first use, and a changed key stops the connection until you decide.

On a network that allows UDP, connect directly with Mosh instead.

Questions

Do I need cloudflared on my phone?

No. moshterm connects to the tunnel's public hostname itself. cloudflared only runs on the computer you connect to.

Does Mosh work through a Cloudflare Tunnel?

No. Mosh needs UDP and the tunnel carries TCP, so sessions through a tunnel use SSH. On networks that allow UDP, connect to the host directly with Mosh.

Why are new connections through the tunnel refused after a while?

OpenSSH 9.8 and later penalize an address after repeated failed or dropped connections, and every tunnel connection comes from cloudflared's loopback address. Add PerSourcePenaltyExemptList 127.0.0.1,::1 to sshd_config and reload sshd.