Skip to content

Mosh

Mosh (mobile shell) runs the terminal over UDP and keeps the session alive when the device’s IP address changes, for example when a phone moves from Wi-Fi to cellular. PocketCmd includes its own Mosh client, which talks to the standard mosh-server on your server.

  • mosh-server on the server. PocketCmd looks for it on the login shell’s PATH and in /opt/homebrew/bin, /usr/local/bin and /usr/bin.
  • SSH access to the server. Mosh is started over SSH.
  • Inbound UDP 60000–61000 open on the server. Each session uses one port from that range.
Terminal window
# Debian / Ubuntu
sudo apt install mosh
# Fedora
sudo dnf install mosh
# macOS (Homebrew)
brew install mosh

More systems are listed in Compare Protocols.

  1. Create or edit the server with its SSH address and credentials.
  2. Tap Test Connection. When the test finds mosh-server, Mosh appears under Protocol.
  3. Select Mosh and save.

Opening a terminal on the server now starts Mosh directly. PocketCmd logs in over SSH, runs mosh-server new and connects to the UDP port it reports. The loading screen shows “Starting mosh-server…” until the session is usable. If mosh-server cannot be started, you get a plain SSH shell instead and the message “Mosh unavailable, using SSH”.

You can also start a single Mosh session on an SSH server from its server sheet without changing the server’s protocol.

A Mosh session keeps running on the server while the device is offline, asleep or on a different network, and the app reattaches to it when the connection returns.

The session also survives closing or restarting PocketCmd. The app stores the session key, sealed with your vault key and reconnects to the same mosh-server the next time you open it. It keeps the key for as long as the server’s MOSH_SERVER_NETWORK_TMOUT allows (read when mosh-server starts), and never longer than 7 days.

The server sheet’s Sessions list shows this device’s saved Mosh sessions with their remaining time (“expires in …”). Tap one to resume it, or long-press for Resume and Kill Session. Closing a session in the app ends its mosh-server as well.

Mosh can show what you type before the server confirms it. PocketCmd turns this on automatically when the measured round trip is longer than 50 ms, and the server’s next screen update confirms or corrects each predicted character.

Mosh synchronizes the screen, not the stream of output. When output scrolls faster than the link can carry it, intermediate lines never reach the device, so local scrollback can have gaps. For complete history, enable tmux for the server: PocketCmd starts the tmux session as the mosh-server command, and tmux keeps every line on the server. See tmux Integration.

Files, workspaces and port forwards on a Mosh server use a separate SSH connection to the same host. Port forwards therefore do not roam with the Mosh session.

With a jump host, the SSH login that starts mosh-server goes through the chain, but the UDP traffic goes straight from the device to the server. The server’s Mosh ports must be reachable from your network.

PocketCmd logged in but could not start mosh-server. Install Mosh on the server, or make sure mosh-server is on the PATH of a login shell or in one of the directories listed above.

The session connects, then stalls with no output

Section titled “The session connects, then stalls with no output”

The SSH login works but the UDP packets do not arrive. Open UDP 60000–61000 in the server’s firewall and in any cloud security group or NAT rule in front of it.

The server form only offers Mosh after Test Connection has found mosh-server. Install it, then run the test again.