Can Mosh Keep My Session Alive After Sleep or a Dropped Connection?

Updated

Yes. Mosh is designed to keep an interactive terminal session alive across laptop sleep and temporary network loss. According to mosh.org, you can put your laptop to sleep and wake it up later "keeping your connection intact," and if your Internet connection drops, Mosh warns you but the connection resumes when network service comes back. This works because Mosh is built for roaming and intermittent connectivity, rather than treating every network change as a reason to start over.

What Mosh actually preserves

Mosh is a remote terminal application and a replacement for interactive SSH terminals. Its selling point is that it stays usable over Wi-Fi, cellular, and long-distance links where SSH tends to stall or disconnect.

Situation What Mosh does
Laptop sleeps, then wakes Connection stays intact
Internet connection drops Mosh warns you
Network service returns Connection resumes
You move between networks (Wi-Fi, Ethernet, LTE) Mosh roams automatically and you stay logged in

The site's own framing is "Change IP. Stay connected." — Mosh automatically roams as you move between Internet connections, so switching from Wi-Fi on a train to Ethernet in a hotel to LTE elsewhere doesn't log you out. Most network programs, including SSH and web apps, lose their connections after roaming; Mosh is the exception described on the site.

Why it survives when SSH doesn't

The mechanism matters if you're deciding whether to rely on it:

  • UDP-based protocol. After the initial login, Mosh runs mosh-server remotely and connects to it over UDP. The site notes this UDP-based protocol handles packet loss gracefully and sets the frame rate based on network conditions.
  • Same login method, different transport. The mosh client logs in to the server via SSH using your existing credentials (password or public key), then hands off to the UDP session. Mosh itself doesn't listen on network ports or authenticate users.
  • No privileged code, no daemon. You don't need superuser rights to install or run Mosh. The client and server are executables run by an ordinary user and last only for the life of the connection — so there's no background service holding things together.

A practical example: you're editing a file in vim over a cellular hotspot, close the lid to board a train, reopen it twenty minutes later on the train's Wi-Fi. With SSH you'd typically find a frozen or dead terminal and reconnect. With Mosh, per the site's description, the session is still there.

What you'll see when the network drops

Mosh doesn't silently pretend everything is fine. When connectivity is lost, it warns you, and the session resumes once the network is back. Separately, Mosh provides intelligent local echo: typing, deleting, and line editing respond instantly instead of waiting for the server's reply. On a bad connection, outstanding predictions are underlined so you aren't misled about what the server has actually received. This is why Mosh feels responsive even when the link is poor — and why it remains usable in full-screen programs like emacs and vim.

Limits worth knowing before you switch

  • UTF-8 only. Mosh was designed from scratch and supports just one character set. The site presents this as fixing Unicode bugs found in other terminals and in SSH, but it does mean non-UTF-8 workflows aren't supported.
  • It's a terminal program, not a GUI. Mosh runs inside xterm, gnome-terminal, urxvt, Terminal.app, iTerm, emacs, screen, or tmux, like ssh.
  • Availability. Mosh is free software available for GNU/Linux, BSD, macOS, Solaris, Android, Chrome, and iOS.
  • Control-C behaves better. Because the UDP protocol doesn't fill up network buffers, the site states Control-C always works to halt a runaway process.

Bottom line

If your concern is losing work when your laptop sleeps or your connection flaps, Mosh is built precisely for that case: sleep and wake keep the connection intact, drops produce a warning, and the session resumes when the network returns. If you need non-UTF-8 character support or a non-terminal interface, look elsewhere. For installation and usage details, the site points to its "Getting Mosh" and "Usage" pages.