Install a Mosh Server as SSH Alternative on Linux

Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Create a Linode account to try this guide with a $ credit.
This credit will be applied to any valid services used during your first  days.

Mosh is a free replacement for SSH that allows roaming and supports intermittent connectivity. Unlike regular SSH connections, Mosh continuously syncs your local and remote sessions to ensure that your client automatically reconnects to the server when you switch between wireless networks or wake your computer from sleep. This guide explains how to install Mosh on your Linode and your personal computer.

Note
Mosh does not support port forwarding or proxying, and you cannot use mosh to copy files or mount remote directories. You’ll still need to use SSH for these tasks.

Mosh SSH Benefits

There are several benefits of using Mosh to connect to your Linode:

  • Continuous Connection: If your network connectivity is interrupted, Mosh will try to reconnect using any available Internet connection.
  • Reduced Network Lag: Unlike SSH, which waits for the server’s response before displaying what you typed, Mosh provides instant responses to typing, deleting, and line editing.
  • Like SSH, Only Better: Mosh runs inside regular terminal applications and logs in to the server via SSH.

Ready to get started? Let’s go!

Preparing Your Firewall

Before installing Mosh, you should verify that your Linode’s firewall will allow the Mosh client and server to communicate. If you followed our instructions to create a firewall with iptables, you’ll need to edit /etc/iptables.firewall.rules and add another rule to allow the Mosh client to connect to your Linode over UDP ports 60000–61000.

File: /etc/iptables.firewall.rules
1
-A INPUT -p udp --dport 60000:61000 -j ACCEPT

Activate the new firewall rule by entering the following command:

sudo iptables-restore < /etc/iptables.firewall.rules

Mosh can now communicate with your Linode.

Install Mosh on Your Linode

First, you need to install Mosh on your Linode. Find the instructions for your Linux distribution below.

Ubuntu

Install mosh from the developer’s PPA repository by entering the following commands, one by one:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:keithw/mosh
sudo apt-get update
sudo apt-get install mosh

Mosh is now installed on your Linode.

Debian

Mosh is available in Debian’s backports repositories. You’ll need to add squeeze-backports to your sources.list, update your package information, then install from the backports repository. Here’s how:

  1. Edit /etc/apt/sources.list and add the following line:

    File: /etc/apt/sources.list
    1
    
    deb <http://backports.debian.org/debian-backports> squeeze-backports main
  2. Run apt-get update.

  3. Install mosh from squeeze-backports by entering the following command:

    apt-get -t squeeze-backports install "mosh"
    

Mosh is now installed on your Linode.

Arch Linux

Mosh is available in the Arch Linux repositories. Enter the following command to install it:

pacman -S mosh

Mosh is now installed on your Linode.

Other Distributions

If you have another Linux distribution installed on your Linode, see the Mosh website for installation instructions.

Install Mosh on Your Desktop Computer

Now you need to install Mosh on your desktop computer. Find the instructions for your computer’s operating system below.

Linux

Follow the instructions for your distribution listed in the Installing Mosh on Your Linode section, or see the Mosh website.

Mac OS X

The easiest way to install Mosh in OS X is to download the installation package from the Mosh website.

Or, if you prefer, you can automate the process of downloading, compiling, and installing Mosh with Homebrew. Note that you must already have Homebrew installed.

brew install mobile-shell

Mosh is now installed on your computer.

Windows

There is not currently a native Mosh client available for the Windows operating system. Please see this issue for additional information.

Connecting with Mosh

The syntax for connecting to a remote server with Mosh is similar to ssh:

mosh yourusername@host.yourdomain.com

Mosh will log in to the server via SSH and then connect on a UDP port between 60000 and 61000.

You can also connect to an SSH daemon that is running on an alternate port:

mosh yourusername@host --ssh="ssh -p 2222"

Congratulations! You’ve just connected to your server with Mosh!

This page was originally published on


Your Feedback Is Important

Let us know if this guide was helpful to you.


Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.
The Disqus commenting system for Linode Docs requires the acceptance of Functional Cookies, which allow us to analyze site usage so we can measure and improve performance. To view and create comments for this article, please update your Cookie Preferences on this website and refresh this web page. Please note: You must have JavaScript enabled in your browser.