Strovent SystemsSign in
Reference

How long a Mosh session lasts

How long Mosh waits for a client that has gone, the 60-second startup limit, and the host settings that end idle or abandoned sessions.

A Mosh session does not time out because you are quiet or because the network is down. By default the host's mosh-server waits for the client for as long as it takes.

Staying connected

Mosh lets you sleep a laptop, change networks or lose signal and carry on when the network returns. The client sends a packet at least every three seconds, and warns you when it has not heard from the server for a while. The session itself stays on the host. See How Mosh works.

What ends a session

  • You log out. exit or logout on the host closes it, and mosh-server quits.
  • You end it from the client. Type the Mosh escape character followed by a period. The default escape character is Ctrl-^ (Control-Shift-6 on a US keyboard). For the OpenSSH equivalent, Enter ~ ., see Kill a frozen SSH session with Enter ~. (OpenSSH escape sequences).
  • Nobody connects after startup. mosh-server exits if no client has contacted it within 60 seconds. This is why a Mosh login that never gets its UDP packets through leaves nothing behind. See What Mosh needs on the host.
  • A timeout the host has set. The variable MOSH_SERVER_NETWORK_TMOUT is a number of seconds. If it is set to a positive integer, mosh-server exits when it has received no update from the client for that long. If it is not set, the server waits with no limit.
  • A signal. SIGUSR1 ends mosh-server. If MOSH_SERVER_SIGNAL_TMOUT is set, the signal is ignored until the client has been silent for that many seconds. That lets an administrator end only disconnected sessions with pkill -SIGUSR1 mosh-server.

Setting the timeouts

The Mosh manual page says the variables are meant for the host, in a login or rc file, either the user's own or a system-wide one. mosh-server passes them to the shell it starts, but changing them inside the session has no effect. Set them before the session starts:

export MOSH_SERVER_NETWORK_TMOUT=604800

The manual page suggests a high value for mobile devices, such as 604800 (one week) or 2592000 (30 days). MOSH_SERVER_NETWORK_TMOUT is not an idle timeout for the login. It only applies to network connectivity: it counts how long the host has gone without an update from the client.

Sources

Spotted a mistake? Email [email protected].