Русский flag Русский

Mosh for Beginners: A Mobile Shell for Remote Access

Published on 2025-10-23

Hello! If you’re new to the world of remote server administration, you’re probably familiar with SSH — a reliable tool for connecting to remote machines. But what do you do when the connection is unstable: Wi‑Fi drops, you switch to mobile data, or your laptop “sleeps”? This is where Mosh (Mobile Shell) comes in — a “mobile shell” that makes remote work comfortable even in poor conditions.

In this article we’ll look at what Mosh is, why it’s better than SSH in certain scenarios, how to install and use it. Everything simple and step‑by‑step — for absolute beginners. Let’s get started!

What is Mosh?

Mosh is a remote terminal tool that replaces interactive SSH sessions. It supports roaming (switching between networks without losing the connection), works with intermittent connectivity, and provides instant local responsiveness to your keypresses. Unlike SSH, where each character waits for server confirmation (creating delays on slow links), Mosh predicts your input and displays it locally immediately, then synchronizes with the server.

Mosh uses the UDP protocol (instead of TCP in SSH), which makes it resilient to packet loss. Authentication happens over SSH, so your passwords and keys remain secure. Mosh is free software under the GPL, and works on Linux, macOS, Windows (via emulators) and even mobile devices.

Short: Mosh is SSH, but “smarter” and mobile. Ideal for developers, system administrators, and anyone working remotely on the go.

Advantages of Mosh over SSH

Here’s why you should try Mosh, especially if you frequently connect to servers:

AdvantageSSHMosh
Roaming between networksConnection drops when IP changes (Wi‑Fi → LTE)Automatically restores, stays logged in
Intermittent connectivitySession breaks when packets are lostKeeps working, warns about problems and recovers
Input latencyYou see characters only after server reply (lag on slow links)Instant local echo: you type as if local, with highlighting of unpredictable characters
Working with editorsDelays in Vim/Emacs are annoyingSmooth operation in fullscreen applications
SecurityTCP, vulnerable to RST attacksUDP with AES encryption, per‑packet authentication
InstallationAlready everywhereRequires installation on client and server, but simple

Mosh doesn’t replace SSH entirely (for file transfer use SCP or rsync), but it’s ideal for interactive terminal work.

Installing Mosh

Mosh needs to be installed on the client machine (your computer) and on the server (the remote machine). It depends on SSH, so make sure SSH is working. Mosh also requires a UTF‑8 locale — check with locale and set LC_CTYPE="en_US.UTF-8" if needed.

On Linux (Ubuntu/Debian)

sudo apt update
sudo apt install mosh

For Fedora: sudo dnf install mosh. Arch: sudo pacman -S mosh.

On macOS

Via Homebrew:

brew install mosh

Or download the .pkg from the official site.

On Windows

Not natively supported, but works via WSL (Windows Subsystem for Linux):

  1. Install WSL and Ubuntu from the Microsoft Store.
  2. In Ubuntu: sudo apt install mosh.
  3. Connect from Windows Terminal: wsl mosh user@server.

Alternatives: Mosh for Chrome (extension) or Cygwin.

On the server: The same — install mosh (this includes mosh-server). Open UDP ports 60000–61000 in the firewall:

sudo ufw allow 60000:61000/udp

If the server is behind NAT (for example, AWS EC2), configure security rules for these ports.

How to use Mosh: Simple examples

Mosh works like SSH: just replace ssh with mosh. It will automatically start SSH for authentication, then switch to UDP.

Basic connection

mosh user@hostname
  • Replace user with your username, hostname with the server IP or domain.
  • Enter your password (or use SSH keys for seamless login).
  • Example: mosh root@192.168.1.100

After connecting you’ll see the server prompt. Type commands — everything will be responsive!

Connecting with a nonstandard SSH port

If SSH is on port 2222:

mosh --ssh="ssh -p 2222" user@hostname

Specifying a UDP port (for firewall)

mosh --server="mosh-server --port=12345" user@hostname

(The server will use UDP port 12345.)

Running a command immediately

mosh user@hostname -- ls -la

(It will run ls -la and exit.)

Ending a session

  • On the server: exit or logout.
  • Or the escape sequence: Ctrl-^ (Ctrl-Shift-6) + . (dot). To enter literally: Ctrl-^ ^.

Tip for beginners: Use tmux or screen on the server to keep sessions. Mosh doesn’t preserve scrollback, but with tmux you can detach and reattach: mosh user@host -- tmux attach.

Troubleshooting and tips

  • “UTF-8 locale” error: Set export LC_ALL=en_US.UTF-8 in ~/.bashrc on both client and server.
  • UDP blocked: Check firewall (ufw, firewalld) and NAT. Test: nc -u -l 60000 on the server.
  • Slow connection: Mosh highlights predictions — this is normal; confirmation will arrive.
  • IPv6: Supported, but roaming only works over IPv4.
  • With tmux/screen: Run them on the server for scrollback and multiwindow.
  • Testing: Connect and try Ctrl-Z (suspend), then fg (resume) — if the session is alive, that’s Mosh!

If problems persist, read the man page: man mosh.

Conclusion

Mosh is a lifesaver for those tired of SSH drops on mobile networks. Install it in 5 minutes, connect — and feel how remote work becomes as smooth as local. Try it on a test server, and you won’t go back to plain SSH for interactive work!

If you have questions or ideas to improve the article — leave a comment. Happy “moshing”! 🚀

Related reviews

Mikhail is an outstanding professional! You can tell he has a great deal of experience. The work was done precisely and on time. We had to tinker a bit because the project installed on the server wasn't perfect, but Mikhail carefully and thoughtfully guided us on what to do and how. In the end, everything worked! I recommend him to anyone who values quality.

N_Konstantin · VPS setup, server setup

A settled customer

2025-10-10 · ⭐ 5/5

Mikhail is an excellent performer! You can tell he has a wealth of experience. The work was done precisely and on time. We had to tinker due to imperfections in the project that was being installed on the server, but Mikhail carefully and thoughtfully advised what to do and how to do it. In the end, everything worked! I recommend him to anyone for whom the quality of work is important!

Need help?

Get in touch with me and I'll help solve the problem

Related Posts