
Mosh (Mobile Shell) Alternative for SSH
- 3 minsDive into Mosh (Mobile Shell)
Mosh—short for Mobile Shell—is a modern alternative to SSH’s terminal interface. Since SSH became the de facto standard around 1995, it has replaced older protocols like telnet, rlogin, and FTP. Mosh builds on SSH’s strengths, adding features that make it far more resilient and user-friendly in real-world conditions like unreliable Wi-Fi, roaming, or high-latency links.
Why Mosh Over SSH?
- Seamless roaming: Uses UDP rather than TCP, allowing sessions to persist even when your IP changes—perfect for moving between networks or waking from sleep.
- It feels faster and more responsive thanks to UDP-based sessions and predictive typing.
- Lag reduction: Includes local echo/predictive typing to maintain responsiveness in slow connections.
- Robust UDP encryption: Each packet is protected with AES‑128, ensuring security over UDP streams.
How It Works Under the Hood
- Initial handshake: Mosh launches
mosh-server
over SSH. Keys are exchanged, then SSH disconnects. - UDP session established: The Mosh client (on your machine) connects over UDP to the server’s port, maintaining stateful interaction independently.
- Encrypted datagrams: Every UDP packet is encrypted end-to-end using AES‑128.
Limitations of Mosh
- Requires opening a UDP port range (60,000–61,000), which may raise firewall and security concerns.
- Lacks SSH-agent forwarding.
- Does not support scrollback history or X11 forwarding.
Prerequisites
- A Linux or macOS machine (client)
- A Linux server (VPS or physical), e.g. Ubuntu 20.04+
- A user account with SSH access
Step 1: Prep Your Server
sudo apt update
sudo apt -y upgrade
Step 2: Install Mosh
#On Ubuntu / Debian:
sudo apt install -y mosh
#On macOS:
brew install mosh
#Verify MOSH installed on both client and server
mosh --version
On Windows:
- You can use the Chrome app or WSMarina; native Windows builds are still emerging.
Step 3: Open UDP Ports (60000–61000)
Configure your firewall (e.g., ufw, iptables) to allow Mosh traffic:
sudo ufw allow 60000:61000/udp
sudo ufw reload
sudo ufw status
Step 4: Check Locales
Mosh requires both client and server to use UTF-8 locales to correctly render text, symbols, and international characters. If one side isn’t using UTF-8, you might see garbled or strange character output in your terminal.
Ensure both client and server use UTF‑8 locales:
locale
# If not UTF‑8:
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# Add to ~/.bash_profile or ~/.profile to make it permanent
Optional: Reconfigure locales on Debian/Ubuntu
sudo dpkg-reconfigure locales
Make sure values like LANG and LC_ALL are set to an UTF‑8 locale (e.g. en_US.UTF-8). If you see blank or “C” values, update your shell config:
Step 5: Connect With Mosh
#Simply swap out ssh for mosh:
mosh user@your.server.address
#Need a custom SSH port? Add:
mosh --ssh="ssh -p 2222" user@your.server.address
Tips & Best Practices
- Pair Mosh with tmux or screen to handle scrollback and reconnections.
- If changing servers or ports frequently, consider using aliases in your ~/.ssh/config.
- Remember: Mosh handles terminal sessions, not file transfers. Use scp or rsync for files.
- SSH remains essential for everyday remote management, file transfers, and secure operations.
- Mosh shines when connections are unreliable: it excels at roaming, handling latency, and supporting session suspension.
- Use Mosh to stay productive over shaky networks—but keep SSH in your toolkit for full-featured remote access.
In Summary
Mosh enhances SSH by enabling roaming, reducing lag, and adding predictive typing, while preserving strong AES‑128 encryption. Whether you’re hopping between networks or working in far-off datacenters, Mosh keeps your session stable and responsive. Watch out, though—the scrollback is minimal; for full terminal history, use it alongside tmux or screen.
Thanks for reading!
—
Guneycan Sanli