Mosh

From PlebNet Wiki
Revision as of 19:48, 2 October 2021 by Lucasdcf (talk | contribs) (Marked this version for translation)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Other languages:
English

Two of the discomforts of using a CLI to SSH into a node are:

  • disconnections
  • latency while typing

Mosh solves these issues and provides a far superior user experience. The key differences are:

  • Mosh uses a persistent UDP connection, sessions remain active even between disconnections or laptop lid closes.
  • Mosh uses predictive typing ("local echo") so typing feels instant, even on remote lightning nodes.

Mosh man page.


Client-side and server-side installation

On linux:

   sudo apt-get install mosh

On OSX:

   brew install mosh


Usage

Instead of typing:

   $ ssh ubuntu@X.X.X.X

You can use mosh:

   $ mosh ubuntu@X.X.X.X

If using a pem file for authentication, instead of:

   $ ssh -i ~/.ssh/my_key.pem ubuntu@X.X.X.X

Use:

   $ mosh --ssh='ssh -i ~/.ssh/my_key.pem' ubuntu@X.X.X.X

That's a rather long command, so you may want to consider setting up an alias, e.g

   $ alias m="mosh --ssh='ssh -i ~/.ssh/my_key.pem' ubuntu@X.X.X.X"


use over slow connections

If you're moshing over a slow connection, or into a very distant lightning node:

   $ mosh --ssh='ssh -i ~/.ssh/my_key.pem' --predict=experimental ubuntu@X.X.X.X 

Experimental prediction provides a totally seamless typing experience on your node, as if you were typing on your localhost's CLI.


Firewall Settings

Mosh uses UDP port 60001, so make sure you open this port in your firewall settings. If you close a terminal without terminating the session, the user can remain logged in, which then occupies the port. For this reason, you may also want to consider opening port 60002. Another option is to ssh in, to kill the zombie session.


Killing Zombie Sessions

If you have a zombie session preventing you from moshing in, simply kill it with:

   $ who -u
   $ ubuntu   pts/1        2021-07-21 12:40   .         22056 (X.X.X.X via mosh [22056])

Then:

   $ pkill -9 22056