Mosh is better for an interactive phone terminal that must recover after network changes; SSH remains better for file transfers, tunnels, and servers you cannot modify. Choose Mosh when UDP is reachable and roaming matters, and keep a server-side recovery plan with either protocol.
Why does SSH disconnect when my phone switches networks?
Ordinary SSH carries terminal traffic over TCP. If switching from Wi-Fi to cellular changes the connection’s network endpoints, that TCP connection cannot simply migrate. A brief signal gap does not necessarily kill SSH immediately, but a broken connection requires a new login connection.
Mosh uses SSH to authenticate and launch mosh-server, then closes that SSH connection. Its interactive traffic moves over UDP. When the server receives an authenticated packet with a newer sequence number, it updates the client’s destination address and port. That is how the same session can follow your phone onto another network.
It also synchronizes the latest terminal screen instead of delivering every intermediate screen update. After leaving a lift with no signal, you can catch up to the current display without replaying all the output generated during the gap. These mechanisms are described in the Mosh protocol paper.
SSH keepalives are a different tool. OpenSSH’s ServerAliveInterval requests a response after an interval without incoming data; ServerAliveCountMax controls how many unanswered requests trigger disconnection. They detect an unresponsive peer, not migrate a dead connection. These are OpenSSH settings, not a claim about settings exposed by every phone app.
How does Mosh make typing feel faster?
Mosh’s predictive local echo draws likely effects of your keystrokes before the server’s reply arrives. It models ordinary typing, backspace, and horizontal cursor movement, and checks its predictions against the server. By default, predictions appear on high-latency connections or during network glitches; unconfirmed cells can be underlined. See the Mosh manual.
This predicts screen changes, not commands you should run. It does not make a restart execute faster or prove that the server received it. During an outage, wait for confirmed output before deciding what happened.
TermAI’s AI assistant addresses a separate problem: remembering the right command on a small screen. It suggests commands for you to review and confirm before execution. Mosh predicts how existing input will look; TermAI helps formulate input. Neither a prediction nor an AI suggestion is evidence that production is healthy.
What do I lose when I use Mosh instead of SSH?
The important boundary is an interactive terminal versus a general SSH transport.
| Requirement | Ordinary SSH | Mosh |
|---|---|---|
| Remote software | A working SSH server | SSH access plus mosh-server |
| Network path | Reachable SSH TCP port | SSH startup plus reachable UDP |
| File transfer | SFTP/SCP through appropriate clients | Separate file-transfer connection needed |
| TCP tunnels and X11 forwarding | Supported by OpenSSH, subject to configuration | Not carried by Mosh |
| SSH agent forwarding | Available with supporting clients and server policy | Not carried by Mosh |
| Terminal history | Depends on the terminal’s buffer | Visible-state synchronization can leave local history incomplete |
OpenSSH documents its forwarding and remote-execution capabilities; Mosh documents its interactive-only scope. A phone app may implement only some SSH features, so this table is not a TermAI feature checklist.
Files: downloading an incident log or uploading a configuration file still needs a separate transfer. TermAI’s SFTP serves that task, even if you use a Mosh-capable app for another terminal session. See SFTP clients for Android.
Forwarding: a database tunnel does not become roaming-capable because you open Mosh alongside it. Keep the tunnel’s SSH connection and recovery requirements separate. See port forwarding from a phone.
Agent forwarding: authenticating the initial login with your key does not make that key’s agent available for an onward connection from the server. Mosh does not relay agent requests, as its author explains in the project mailing list.
Scrollback: do not treat swiping upward as a complete record of a noisy command. Mosh’s official FAQ confirms that local history can be incomplete and recommends server-side tmux or screen. For incident evidence, retain logs on the server and retrieve the relevant file instead of relying on terminal history alone.
What do I need to use Mosh on my phone?
Prepare it before an incident:
- Choose a phone client that explicitly supports Mosh. Installing it only on the server does not add support to an SSH-only app.
- Install
mosh-serveron the target host and make it available to the login environment. It runs without root privileges, but installation and network changes still need to fit your server policy. - Ensure a working UTF-8 locale and normal SSH authentication.
- Permit the selected UDP port through the actual path: host firewall, cloud firewall, and any server-side NAT. The documented default range is UDP 60000–61000; a configured smaller range or selected port can be used. TCP access alone is insufficient.
These requirements and port selection are covered by the Mosh usage guide. Public or corporate networks may block the needed UDP traffic even when SSH works.
In a local command-line environment with Mosh installed, the basic connection is:
mosh user@server
Replace the placeholders with your account and host. In a native phone client, use its Mosh connection option. Typing this inside an existing TermAI SSH session would launch it on the remote machine; it would not convert the phone’s connection.
If startup reports mosh-server missing, check installation and its executable path. If SSH authentication succeeds but no UDP reply arrives, investigate the UDP path rather than changing the SSH key. The official troubleshooting FAQ distinguishes these failures.
Will Mosh survive locking my phone or closing the app?
Separate a network interruption from losing the client process. Locking a screen is not a universal promise of either disconnection or survival. On iOS, background execution is limited and apps may be suspended; see Apple’s background-execution documentation.
Mosh can wait through a connectivity gap, but recovery still needs usable client session state and a living server process. A force-quit or phone reboot should not be treated like a temporary radio outage. Test your particular app’s restoration behavior.
Server policy matters too: MOSH_SERVER_NETWORK_TMOUT can terminate an unreachable session after a configured interval. Without that timeout, the server normally waits indefinitely for the client to return. The mosh-server manual documents this behavior. A server reboot or termination of that process ends this recovery path.
Before relying on either protocol, practice switching networks, locking and unlocking the phone, and reopening the app with a disposable session. Observe which cases resume and which require reattachment. Do not make a production restart your first test.
When should I choose Mosh over SSH on a phone?
Choose Mosh for sustained interactive work while moving: editing a file on a laggy connection, checking a live terminal dashboard during a commute, or repeatedly switching between Wi-Fi and cellular. It is a strong choice when you control server setup and have tested UDP reachability.
Choose SSH for a short check, SFTP transfer, tunnel, or restricted host. If the task is downloading an existing diagnostic bundle, Mosh adds no file-transfer capability. If policy permits only the established SSH path, use that path and prepare to reconnect. SSH also remains the appropriate transport for non-interactive tools and automation.
Use both when tasks differ. A Mosh terminal and a separate SSH/SFTP connection can be sensible companions. Select by the operation you need to complete, rather than trying to make one protocol cover every job.
How should I handle dropped SSH connections in TermAI?
TermAI provides SSH/SFTP on iOS and Android, built-in Tailscale, and AI command suggestions that require confirmation. Mosh support is not confirmed here. The practical TermAI workflow is to combine its SSH access with a recoverable workspace on the server.
Use built-in Tailscale when the target is reachable through your authorized tailnet. Tailscale provides stable private addresses, so the host’s address need not follow changes to its physical network. Treat this as network reachability, not a guarantee that an SSH session survives every interruption.
On a server with tmux already installed, open TermAI’s SSH connection and create a named workspace:
tmux new-session -s mobile-ops
After an SSH disconnect, reconnect to the same host as the same user and attach:
tmux attach-session -t mobile-ops
An explicit attach is useful during recovery: if the session is missing, investigate before creating a replacement and repeating work. tmux keeps its workspace on the server, and its copy mode provides retained terminal history. These commands and behavior are documented in the tmux getting-started guide. Persistence here depends on the tmux server and its processes remaining alive.
If you need command help, ask TermAI’s assistant: “Suggest a read-only check for the service named in my incident runbook; do not suggest restarting it yet.” Review the service name, flags, and scope before confirming. After any interrupted change, inspect service and job status before retrying: a missing reply does not establish failure. Follow the phone-only incident runbook for that verification sequence.
Use SFTP to retrieve a retained diagnostic file when you need to review or hand off evidence. TermAI’s free tier includes unlimited SSH/SFTP and five AI requests per day; keep your recovery commands available without depending on an AI request. For an SSH/SFTP-first workflow, start with TermAI and rehearse reconnection before the next alert.
What else should I know about Mosh vs SSH?
Does Mosh replace SSH?
It replaces the interactive transport after SSH startup. Keep SSH for file transfers, forwarding, and non-interactive workflows.
Is Mosh more secure than SSH?
Roaming is not a security ranking. Mosh uses SSH during startup, then separately encrypts and authenticates UDP traffic. Its protocol design explains that distinction. Keep host verification and server maintenance in place with either choice.
Can I transfer files while using Mosh?
Yes, through a separate SSH-based file-transfer connection. TermAI provides SFTP for this part of your workflow; the files do not travel through Mosh.
Do I still need tmux with Mosh?
Use it for retained server-side history and a workspace accessible through a fresh connection. Neither tool preserves running processes through a server reboot.
Does TermAI support Mosh?
Mosh support is not confirmed here. TermAI provides SSH/SFTP, built-in Tailscale, and AI suggestions you confirm. This guide’s TermAI recovery procedure uses ordinary SSH plus server-side tmux.
Free on iOS and Android. 5 AI requests/day on the free tier, plus unlimited SSH/SFTP and built-in Tailscale.