601 字
3 分钟

Fix High VPS Latency on Ubuntu by Replacing SSH with Mosh

Mobile Shell (Mosh) is a free and fast remote terminal application. It supports roaming, works with intermittent connections, and provides smart local echo and line editing for user keystrokes. You already know SSH; Mosh is designed for the typical interactive use cases of SSH. Because Mosh is more robust and responsive—especially over Wi‑Fi, cellular, and long-distance links—it’s considered a strong alternative for interactive SSH terminals. Mosh is also available for almost all GNU/Linux, FreeBSD, Solaris, macOS, and Android systems.

What Is Mosh and How Does It Work?#

Mosh is free command-line software used to connect from a client machine to a server over the Internet to run a remote terminal. It’s available on GNU/Linux, BSD, macOS, Solaris, Android, Chrome, and iOS. Mosh is similar to SSH but adds features specifically aimed at improving usability for mobile users.

Mosh is smarter than SSH. While an SSH client waits for a TCP response from the server before displaying your input, Mosh shows your keystrokes in real time and can even provide underlined input prediction. The mosh program first connects to user@host via SSH to establish the session. As you know, SSH may prompt the user for a password or use public key authentication to log in. But Mosh then starts a mosh-server process on the server machine (under your user account). In this way, compared with a traditional SSH connection, Mosh brings some clear advantages.

On links with long latency or unreliable connectivity, Mosh is faster and more responsive. So it’s fair to say Mosh is a solid replacement for SSH in many scenarios. When the connection drops, Mosh automatically tries to reconnect—even without you noticing.

Let’s review the key reasons to use Mosh instead of SSH:

1- Mosh keeps your session alive even if your IP address changes.

2- When your network comes back after losing Internet connectivity, or after you suspend and resume your system, Mosh restores the connection to your remote machine.

3- You don’t need superuser (root) privileges to install or run Mosh.

4- The Mosh client logs into the server via SSH, using the same credentials as before.

5- Mosh runs inside your existing terminal emulator, such as xterm, gnome-terminal, urxvt, Terminal.app, iTerm, emacs, screen, or tmux.

6- Unlike SSH, Mosh does not fill up network buffers, so Control-C can always stop a runaway process. For example, if you accidentally request a 200MB file instead of 100MB, you can stop it immediately by pressing CTRL+C.

Advantages of the Mosh Shell#

Now that you know more about Mosh Shell, if you’re still unsure whether to replace SSH with it, check the list below:

1- Mosh is highly efficient.

2- Mosh works well on low-bandwidth or intermittent connections.

3- Like Eternal Terminal (ET), connections persist across Wi‑Fi changes and temporary outages.

4- Mosh lets you keep typing even while SSH and ET are still waiting for a command to complete or for the connection to be re-established.

5- It has built-in mechanisms to handle packet loss.

6- Mosh can log in using the same familiar methods as SSH.

How to Install Mosh Shell on Ubuntu 20.04#

To install the Mosh package on your Ubuntu 20.04 system, simply run the following commands:

Terminal window
apt-get update -y
Terminal window
apt-get install mosh -y

Note If you are running a firewall such as iptables, manually open these ports with the following command:

Terminal window
sudo iptables -I INPUT 1 -p udp --dport 60000:61000 -j ACCEPT

Configure Mosh Shell as an SSH Alternative on Ubuntu Linux#

Once Mosh Shell is installed, you can start using it. Run the following command to connect to your remote system:

Terminal window
mosh root@Your_IP_Address

You should now be able to connect to your remote system. You can also check the installed Mosh version by running:

Terminal window
mosh--version

Mosh supports many options. To see all available options, type:

Terminal window
mosh--help
Fix High VPS Latency on Ubuntu by Replacing SSH with Mosh
https://catcat.blog/en/configuring-mosh-shell-as-a-fast-and-robust-ssh-alternative-on-ubuntu-20-04.html
作者
猫猫博客
发布于
2023-03-14
许可协议
CC BY-NC-SA 4.0