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 VPS and your personal computer.

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.


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

  • 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 VPS'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 VPS over UDP ports 60000–61000.

  -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 VPS.

Installing Mosh on Your VPS

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


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 VPS.


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:

      deb <> 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 VPS.

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 VPS.

Other Distributions

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

Installing 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.


Follow the instructions for your distribution listed in the Installing Mosh on Your VPS 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.


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 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!


  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Using PuTTY

PuTTY is a free, open source SSH client for Windows and UNIX systems. It provides easy...

Use Public Key Authentication with SSH

Public key authentication provides SSH users with the convenience of logging in to their kloud51s...

Using GNU Screen to Manage Persistent Terminal Sessions

GNU Screen is a tool which works with a terminal session to allow users to resume a session after...

Using SSHFS on Linux and MacOS X

SSHFS allows users to securely access remote filesystems over the SSH protocol. This guide will...

Setting up an SSH Tunnel with Your Linode for Safe Browsing

Often you may need to browse the web from a public Wi-Fi access point, such as a coffee shop or...