Strovent SystemsSign in
Reference

How Mosh works

Why Mosh survives roaming and sleep, how it starts over SSH, and what it cannot do.

Mosh (mobile shell) is a remote terminal built for phones, laptops and bad networks. It keeps a session alive when your IP address changes, when you close the lid, or when the signal drops for a while.

How it starts

  1. The client logs in with SSH (so you authenticate the usual way).
  2. SSH runs mosh-server on the host. The server picks a UDP port and creates a random session key.
  3. The SSH connection ends. The client now talks to the server over UDP using that key.

SSH is only used to log in and start the server. It is not used for the session itself.

State synchronization

SSH sends a stream of bytes and, if packets are lost, waits and resends them in order. Mosh works differently. The server keeps the screen state, and the two sides keep their copies in step. The protocol is called SSP (State Synchronization Protocol). If a network packet is lost, the next one carries the latest state, so you do not see old output replay.

Roaming

Each datagram is encrypted and numbered. The server accepts a valid datagram from any address. When you switch from Wi-Fi to mobile data, the next datagram carries the session on without a new login.

Local echo

Mosh predicts what the screen will show when you type and displays it at once, usually underlined until the server confirms. Typing feels instant even at high latency. A wrong prediction is corrected when the real screen arrives.

What Mosh does not do

  • No port forwarding, and no X11 or agent forwarding. These need SSH. For agent forwarding, see Mosh and SSH agent forwarding: why ssh -A does not carry over.
  • No scrollback of its own from the server: you see the current screen. Use tmux or screen on the host for history.
  • It sends screen updates, not a raw byte stream, so it is not suited to file transfer or to programs that use the terminal as a data pipe.
  • It needs UDP to reach the host.

Security

The protocol is encrypted and authenticated with AES-128 in OCB mode. The key is created per session and sent only over the SSH connection.

Spotted a mistake? Email [email protected].