Mosh (the mobile shell) is a remote terminal that keeps a session alive when your network changes or your laptop sleeps. It logs in with SSH, then hands the session over to its own UDP protocol. SSH runs over a single TCP connection, which ends when the network under it changes.
Mosh looks after the connection; Tmux, which runs on the server, looks after the session. They can be used together, or Tmux can carry the load over plain SSH. This page covers what each one does.
When you run mosh user@host:
~/.ssh/config.mosh-server on the remote machine, which picks a UDP port (60000 to 61000 by default) and a session key.mosh-client on your machine and mosh-server talk directly over UDP, encrypted with that key.Because UDP has no connection to break, the client can change IP address, from home wifi to a phone hotspot to office wifi, and the server just starts replying to the new address. A laptop that sleeps for an hour wakes up to the same session. Mosh also predicts what your keystrokes will do and shows them straight away, underlined until the server confirms, which makes a laggy link feel much closer to local.
| SSH | Mosh | |
|---|---|---|
| Transport | TCP, one connection | SSH to start, then UDP |
| Network change (wifi to mobile) | Connection drops | Session carries on |
| Laptop sleep | Usually drops | Session carries on |
| Typing on a slow link | Each key waits for the server | Local echo, confirmed later |
| Scrollback | Your terminal keeps it | Not kept; only the current screen is synced |
| Port forwarding, agent forwarding, file transfer | Yes | No (use SSH for these) |
| Server requirements | An SSH server | SSH server, mosh-server installed, UDP ports open, a UTF-8 locale |
| Installed by default | Almost everywhere | Rarely |
mosh-server stays on the server until it's killed. Tmux inside Mosh is the usual answer.Install it on both ends:
# macOS
brew install mosh
# Ubuntu or Debian
sudo apt install mosh
Open the UDP ports on the server if it runs a firewall. With ufw:
sudo ufw allow 60000:61000/udp
Then connect the way you would with SSH:
mosh user@host
A few useful forms:
| Command | What it does |
|---|---|
mosh --ssh="ssh -p 2222" user@host | The SSH login uses port 2222 |
mosh -p 60001 user@host | Use one fixed UDP port, so only that port needs opening |
mosh user@host -- tmux new -A -s main | Start or re-attach a Tmux session inside Mosh. The -- is required; without it Mosh tries to read Tmux's flags as its own |
Tmux runs on the server and keeps the session there whether or not anyone is connected. When an SSH connection drops, the session detaches and everything in it keeps running. Reconnect and attach, and you're back on the same screen:
ssh user@host
tmux new -A -s main
Compared with Mosh, that costs a reconnect after each drop, and there's no local echo on a laggy link. In return it needs nothing beyond SSH and Tmux, works through firewalls that block UDP, keeps a full scrollback, can be attached from any device, and leaves port and agent forwarding available. The attach and detach guide has the commands.
Running both is common, and they don't get in each other's way: mosh user@host -- tmux new -A -s main.
Shell Drop is SSH only and doesn't have Mosh. Keeping a session alive falls to Tmux on the server: a dropped connection only detaches the session, Shell Drop reconnects after a drop and re-attaches your Tmux session, and restored tabs can re-attach to their sessions by name. Background sessions keep running while you use other apps.
If Mosh is a requirement, Blink Shell, Prompt 3, Termius and WebSSH support it on iOS; the best SSH client for iPhone and iPad roundup compares them. For the SSH-plus-Tmux route on a phone, see SSH on iPhone and SSH on iPad.
Mosh, the mobile shell, is a remote terminal program that replaces the interactive part of SSH. It logs in with SSH, then runs the session over UDP so it survives network changes and sleep, and it echoes your typing locally on slow links.
Not entirely. Mosh uses SSH to log in and start mosh-server, so the server still needs SSH. It replaces only the interactive terminal session; port forwarding, file transfer and other SSH uses still need SSH.
Mosh authenticates through SSH and encrypts its own UDP traffic (AES-128 in OCB mode). The extra exposure is the UDP port range, 60000 to 61000 by default, which has to be open on the server.
Often, yes. Mosh doesn't keep a scrollback history, and a Mosh session can't be re-attached from a new client. Running Tmux inside Mosh gives you both: Mosh holds the connection, Tmux holds the session.
No. Shell Drop is SSH only. It reconnects after a drop and re-attaches your Tmux session. On iOS, Blink Shell, Prompt 3, Termius and WebSSH support Mosh.