📜 ⬆️ ⬇️

Mosh - SSH with blackjack and roaming

On Habré, a couple of years ago , Mosh was already mentioned, but it seems to make sense to remind the masters of this magnificent program, which, quite possibly, will be for someone one of the most pleasant discoveries and make life easier.

Looking ahead, a spoiler right away - for mosh, no superuser rights are needed , it is not a daemon , and does not deal with authentication and encryption (it remains on ssh's shoulders). Developed it at MIT, actively develop, and support for all platforms and distributions.


')
What is mosh better than the traditional ssh-client, what problems does it solve and why do you most likely switch to it?

The main tasks that mosh solves:


Under the hood


The mosh session looks like this.
  1. mosh logs in to the server via SSH and starts a remote mosh-server process that listens on UDP ports from 60000 to 61000
  2. closes an SSH connection
  3. starts the mosh-client with the mosh-server parameters obtained in step 1


Technical details


As a rule, remote-shell protocols profess the approach “the server sends all data to the client, and the client already understands how to display them”. Mosh goes the other way and stores the state of the screen on the client and the server, and these two states are constantly synchronized - in fact, the protocol is called - State Synchronization Protocol. The protocol allows you to control the synchronization frequency, depending on the quality of the network connection.

Separately, the mosh authors are proud from scratch of the UTF-8 emulation of the terminal - mosh perfectly resolves all problems with UTF-8, with “hieroglyphs” and escape sequences. As they write:
“ISO 2022 locking escape sequences oh flying spaghetti monster please kill me now.”
- actual USENIX peer review from the Mosh paper.

(Why should you worry about it, even if you are a reviewer?)


“Why should you trust Mosh with your needs for a remote shell: we take care of the details so hidden that even the USENIX reviewers don’t want to hear about them.”

Demo


As they say, it's better to see once:


Examples


Using mosh is as easy as the usual ssh - in most cases, just change ssh to mosh:
$ mosh myhost.com 

 $ mosh user@myhost.com 

Run an interactive command instead of $ SHELL:
 $ mosh myhost.com top 

Other server port:
 $ mosh --ssh="ssh -p 2222" myhost.com 

Other ssh client options:
 mosh --ssh="~/bin/ssh -i ./identity" myhost.com 


Minuses


From personal experience, I had to stumble on two points:
  1. Ports: on the server where the firewall strictly castrates the ports, there is not a single UDP port that could be enabled for mosh and there is no way to change this - there mosh will not work. However, such situations are rare - as a rule, it is always possible to open an additional port if necessary.
  2. Habit scroll up in the terminal: in mosh it does not work. You have to use more pagers like more or less to view long output.

The rest of the nuances, like “does not yet support IPv6,” I find it difficult to attribute to minuses.

Summary


For me, mosh has become one of the most useful discoveries lately, which freed me the time that was previously spent on reconnecting. Apart from the aforementioned nuances, with the habit of scrolling, the rest of the experience with the remote shell did not hurt in any way. Only now I calmly close the laptop in an open mosh-session and, opening two hours later, I continue from the same place.
Hopefully someone will come in handy as well.

Links


Introductory video about mosh, recommended:



Official site:
mosh.mit.edu

Source: https://habr.com/ru/post/243651/


All Articles