Skip to content

mosh - UDP based SSH tool in Linux

Introduction

When it comes to remote access on Linux, SSH has been the go-to protocol for a long time. However, SSH is not without its shortcomings, particularly when it comes to network connectivity issues. This is where Mosh comes in. Mosh is a remote terminal application that uses UDP instead of TCP to connect to the server. This allows for better connectivity, especially over unreliable or high-latency networks. In this blog post, we’ll take a closer look at Mosh and its benefits.

Benefits of using Mosh

Improved connectivity

Mosh uses UDP instead of TCP, which means it can work better over unreliable or high-latency networks. This is because UDP doesn’t require a connection to be established before data can be sent, unlike TCP. This makes Mosh more resilient to network interruptions such as packet loss or high latency.

Persistent connections

Mosh maintains a persistent connection to the server, even if the client’s IP address changes. This means that if you’re on a mobile device and you switch from Wi-Fi to cellular data, or you move to a different location, your Mosh session will remain active.

Enhanced usability

Mosh has several features that make it more user-friendly than SSH. For example, Mosh supports predictive local echo, which means that when you type a command, you can see the output immediately, even before it’s received by the server. Mosh also supports line editing, which allows you to edit your commands before sending them to the server.

Usage

TCP over UDP

  1. Install mosh
yum install epel-release
yum install mosh

apt install mosh
  1. Connect using the client
mosh user@ip -p 60001
  1. View mosh connections (default UDP port 60001, firewall needs to be opened)
netstat -unlp | grep mosh

UDP mode

  1. Start the mosh-server
mosh-server new -c 256 -s -l LANG=en_US.UTF-8 -p 60000

Shown below:

mosh-server (mosh 1.3.0) [build mosh 1.3.0]
Copyright 2012 Keith Winstein <mosh-devel@mit.edu>
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
  1. Connect using the generated key with mosh-client
MOSH_KEY=9S9Bz/KDYVMNyiJg2267nw mosh-client ip 60000

Note: If a character set problem is prompted, add the following to ~/.bashrc:

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

Conclusion

Mosh is a fantastic tool for remote access on Linux. It offers better connectivity, persistent connections, and enhanced usability compared to SSH. If you frequently access remote servers and you’re tired of dealing with SSH’s limitations, give Mosh a try. You won’t be disappointed!

Reference

  • https://mosh.org/
Feedback