I use mosh when I want to insure connections are not lost / dropped / frozen / etc and if lost or sessions are closed can just login and pick up where it was before.
See
Gemini AI from Google Search results:
Mosh (Mobile Shell) is an alternative to SSH designed to improve the interactive experience of remote terminal sessions, particularly in environments with high latency, intermittent connectivity, or roaming IP addresses. While Mosh uses SSH for initial authentication, it fundamentally differs in how it handles the ongoing session.
Key Features and Differences from SSH:
Mosh sessions remain active even if the client temporarily loses its network connection or changes IP addresses (e.g., switching between Wi-Fi and cellular data). This is a significant advantage over SSH, which typically terminates the session upon network interruption.
Mosh allows the client and server to "roam" and change IP addresses without breaking the connection, making it ideal for mobile users or those frequently switching networks.
- Local Echo and Responsiveness:
Mosh employs a predictive model to provide immediate local echo of keystrokes and line editing, making typing feel more responsive on high-latency connections by reducing the perceived lag.
Unlike SSH, which uses TCP, Mosh utilizes UDP (User Datagram Protocol) for the main session data transfer, enhancing its ability to handle packet loss and network changes. It uses AES-128 OCB mode encryption for secure communication over UDP.
Mosh leverages OpenSSH for the initial authentication process, ensuring a secure and familiar method for establishing the connection.
Mosh typically uses UDP ports in the range of 60,000 to 61,000 for its session data, while still relying on SSH's configured port (defaulting to 22) for the initial authentication.
Neo's Note:
Scrolling back in text sessions do not work well (or at all) with mosh, so if you are working on a task and need to scroll up and down in the terminal window, mosh is not ideal. Otherwise, it's great.