Mosh, also known as Mobile Shell, is an alternative to SSH, the interactive terminal.

Mosh has the following advantages over SSH:

  • Mosh connection is not affected when switching between wifi and cellular data.
  • Always be connected. The computer can sleep at any time and wake up with the MOSH connection intact unless you kill the process manually.
  • No network delay. SSH waits for a response from the server as you type. Mosh, on the other hand, responds instantly to input, delete, and edit lines, giving you a silky feel.

Working principles of MOSH

Mosh consists of two programs, mosh-client and mosh-server. Mosh needs to be installed on both the client and server, but there is no need to manually start mosh-client or mosh-server, because both programs are automatically started each time mosh is used.

By default, mosh connects to the server over SSH and starts mosh-server on the server. He then closes the SSH connection, starts mosh-client on the client side and connects to the server via UDP.

This connection remains, and the user can use MOsh to do everything SSH used to do. Unless the mosh-client is killed, the connection remains regardless of network disconnection or client exception.

Ps.mosh uses ports 60000 to 61000.

How to install

Ps. This document only applies to CentOS. For installation of other oss, see the MOSH official website

The fastest way to install CentOS is using yum.

yum install mosh
Copy the code

Expand yum source

  1. First, check your CentOS version. Different system versions correspond to different EPEL libraries.
    cat /etc/redhat-release
    Copy the code

  1. Install ePEL storage. The operating system of the author is CentOS 7, so you need to execute:

    yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    Copy the code

    For other CentOS systems, the command can be obtained from EPEL Wiki.

  2. Enable ePEL storage.

    # Enable ePEL repository
    yum-config-manager --enable epel
    Refresh the warehouse cache
    yum clean all && yum makecache
    Copy the code
  3. View a list of enabled warehouses.

    yum repolist
    Copy the code

  1. Mosh can now be installed without manual boot after installation.
    yum -y install mosh
    Copy the code

How to run

  1. If you haven’t changed SSH ports, just do it on the client side
Mosh [email protected]Copy the code
  1. If the SSH port has been changed, run -p to specify the SSH port. Note that -p is uppercase. I _ I.
Mosh -p 29806 [email protected]Copy the code

The last

Mosh is not all good either. It has a bug that only displays the content of the last screen when output exceeds one screen and does not support rollback. So you need to see all the output, but after the command plus “| less” to turn the page view.

But that’s a really trivial problem compared to being wired forever and silky smooth.

I heard that this issue will be fixed in a new version, so stay tuned.

Last but not least, I recommend an app, ios Blink, which can connect to the server and support MOsh. Every time mosh connects to the server, no matter how long the iPad is on standby, you don’t need to worry about dropping the connection