Mosh - SSH with blackjack and roaming
Mosh was already mentioned a couple of years ago on Habré , but it seems to make sense to remind the harazhiteli about this magnificent program, which, quite possibly, will become for someone one of the most pleasant discoveries and make life easier.
Looking ahead, there’s a spoiler right away - for mosh, you do not need superuser rights, he is not a demon , and he does not do authentication and encryption (this remains on the shoulders of ssh). We developed it at MIT, are actively developing it, and support it for all platforms and distributions.
Why is mosh better than traditional ssh-client, what problems does it solve, and why are you likely to switch to it?
The main tasks that mosh solves:
Mosh session is as follows
As a rule, remote-shell protocols adhere to the approach "the server sends all the 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 server, and these two states are constantly synchronized - in fact, the protocol is called the State Synchronization Protocol. The protocol allows you to control the frequency of synchronization, depending on the quality of the network connection.
Separately, mosh authors are proud of the emulation of the UTF-8 terminal written from scratch - mosh flawlessly resolves all problems with UTF-8, with "hieroglyphs" and escape sequences. As they write:
“Why should you trust Mosh with your needs for a remote shell: we care about details so hidden that even USENIX reviewers do not want to hear about them.”
As they say, it is better to see once:
Using mosh is as simple as the usual ssh - in most cases, just change ssh to mosh:
Run an interactive command instead of $ SHELL:
Another server port:
Other ssh client options:
From personal experience, I had to come across two points:
The rest of the nuances, such as “does not yet support IPv6,” are difficult for me to attribute to the minuses.
For me, mosh has become one of the most useful discoveries in recent years, which freed me up the time that was previously spent on reconnecting. In addition to the above nuances with the habit of scrolling, otherwise the experience with the remote shell was not affected. Only now I calmly close the laptop in an open mosh session and, after opening two hours later, I continue from the same place.
Hope someone comes in handy too.
Introductory video about mosh, recommended:
Official website:
mosh.mit.edu
Looking ahead, there’s a spoiler right away - for mosh, you do not need superuser rights, he is not a demon , and he does not do authentication and encryption (this remains on the shoulders of ssh). We developed it at MIT, are actively developing it, and support it for all platforms and distributions.
Why is mosh better than traditional ssh-client, what problems does it solve, and why are you likely to switch to it?
The main tasks that mosh solves:
- Possibility of roaming ssh connections . Switch between wi-fi networks, do not be afraid of changing IP in mobile networks - the connection will not break
- Reducing lags as much as possible through the use of UDP and smart predictive echo
- Network Usage Optimization - The mosh protocol allows you to transfer only what needs to be displayed. As a result, Ctrl-C works instantly , even if you spit out the contents of a 500GB file in the console
- Maximum backward compatibility - minimum user gestures and knowledge required to start using mosh
Under the hood
Mosh session is as follows
- mosh logs on to the server via SSH and starts the remote mosh-server process, which listens on UDP ports from 60,000 to 61,000
- closes SSH connection
- starts mosh-client with the mosh server settings obtained in step 1
Technical details
As a rule, remote-shell protocols adhere to the approach "the server sends all the 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 server, and these two states are constantly synchronized - in fact, the protocol is called the State Synchronization Protocol. The protocol allows you to control the frequency of synchronization, depending on the quality of the network connection.
Separately, mosh authors are proud of the emulation of the UTF-8 terminal written from scratch - mosh flawlessly 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 you should trust Mosh with your remote terminal needs: we worry about details so obscure, even USENIX reviewers don't want to hear about them.)
“Why should you trust Mosh with your needs for a remote shell: we care about details so hidden that even USENIX reviewers do not want to hear about them.”
Demo
As they say, it is better to see once:
Examples
Using mosh is as simple 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
Another 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 come across two points:
- Ports: on a server where the firewall strictly castrates ports, there is not a single UDP port that could be used for mosh and there is no way to change it - there mosh will not work. However, such situations are rare - as a rule, there is always the opportunity to open an additional port if necessary
- The habit of scrolling up in the terminal: in mosh, this does not work. You have to use pagers like more or less more often to view long output.
The rest of the nuances, such as “does not yet support IPv6,” are difficult for me to attribute to the minuses.
Summary
For me, mosh has become one of the most useful discoveries in recent years, which freed me up the time that was previously spent on reconnecting. In addition to the above nuances with the habit of scrolling, otherwise the experience with the remote shell was not affected. Only now I calmly close the laptop in an open mosh session and, after opening two hours later, I continue from the same place.
Hope someone comes in handy too.
References
Introductory video about mosh, recommended:
Official website:
mosh.mit.edu