Overview


See https://mosh.org


Using Mosh with JuiceSSH has the following benefits:


  • JuiceSSH will use less battery when long-running Mosh sessions are left in the background
  • Better responsiveness over higher latency connections (e.g. 3G/4G)
  • You can roam between networks (e.g. mobile data and wifi) without losing your session


When you specify the connection type in JuiceSSH as Mosh, JuiceSSH will first SSH into your host and launch a new Mosh server. JuiceSSH will obtain from that server the connection key, and the port to connect to. JuiceSSH will then terminate the SSH session, and use a Mosh client baked into the app to connect back to the session over the Mosh protocol. 


When you leave a Mosh session running in the background on your device, JuiceSSH will send a SIGSTOP to the mosh-client process on your device, to pause the process. When you resume the session in JuiceSSH, it will send a SIGCONT to wake the process up, and continue your session.


Requirements


JuiceSSH requires Mosh version v1.2.5 or above to be installed on your SSH host.


Mosh also requires UDP connectivity between your device, and JuiceSSH. If you are trying to use Mosh to connect to a host over the internet, you will need to forward UDP ports 60000-60100 to your host machine (the number of ports you open is up to you, but each concurrent mosh session will consume a port).


Installation


Mosh is included in most Linux distributions.


Ubuntu / Debian: apt-get install mosh

Arch Linux: pacman -S mosh

CentOS: A mosh package can be found in the EPEL repository


Check the version installed with: mosh-server --version


There is no configuration of mosh-server required.



My Distribution of Linux does not include the correct version of Mosh


If you are using an older distribution of Linux (e.g. Debian Jesse) that does not include Mosh v1.2.5 or greater, you can compile Mosh from source with the following commands:


# Remove any previous version of Mosh that you have installed
$ sudo apt-get remove mosh

# Install Mosh dependencies
$ sudo apt-get install build-essential libssl-dev protobuf-compiler libncurses-dev

# Clone the latest version of Mosh (v1.3.2 at the time of writing)
$ git clone --branch mosh-1.3.2 --depth 1 https://github.com/mobile-shell/mosh.git 
$ cd mosh

# Compile and install
$ ./autogen.sh
$ ./configure --prefix=/usr
$ make
$ sudo make install

Troubleshooting / Common Errors


Could not auto-detect Mosh port/key


If you are seeing this error, then it's likely because your system does not have the locale that JuiceSSH is trying to launch the Mosh server with.


Mosh requires a locale to be specified when launching the server, and for that locale to be present on the host.


To overcome this, you should first check which locales are available on your server with 'locale -a'. By default, JuiceSSH will try to use en_US.UTF-8. If that locale isn't present (or en_US.utf8), then you will need to override the locale setting in JuiceSSH.


You can either do this globally for all connections in JuiceSSH (by changing it in the main JuiceSSH settings under the Mosh Command setting), or on a per-connection basis, by long pressing the connection in JuiceSSH and selecting edit.


Change the locale in the Mosh Server Command to match one that you have available on your host.



Could not spawn a Mosh server on destination host


If this occurs, then it's probably because the mosh-server binary is not in your default path on the host.


Try symlinking the mosh-server into /usr/bin, or updating your default path to include the location that your mosh-server binary is located.