Setup mosh with OSX & ZSH and Ubuntu server

Background and installation

ZSH packed with oh-my-zsh configuration framework and minor customizations has been my preferred shell for around three years.

When configuring servers I’ve been connecting with plain ssh and making edits with mg (Micro Emacs) text editor running on tmux session. Though having used mosh previously I stopped using it at some point and forgot to set it on for my current Contabo VPS.

Mosh “The Mobile Shell” is a simple replacement for the regular ssh command that enchances the ssh client with few cool tricks. For me the main benefits are that it allows connections to persist over network changes and it helps reducing effects of network latency when working with command line tools (very good when working with mobile data connection). It installs nicely for both systems: sudo apt-get install mosh on Linux and brew install mobile-shell on OSX side. Server with a firewall needs to be configured for incoming Mosh UPD data (default port 60001) sudo ufw allow 60001.

Connection problem

Connecting to my server mosh didn’t work and the problem at this point was that my local shell was not sending a proper LANG environment variable for the host, leaving me with the following output:

~$ mosh
mosh-server needs a UTF-8 native locale to run.

Unfortunately, the local environment (LC_CTYPE=) specifies
the character set "ISO-8859-1",

The client-supplied environment (LC_CTYPE=) specifies
the character set "US-ASCII".


Local machine configuration

I succeeded to fix that by configuring my local OSX machine (El Capitan on X220) LANG value and to pass it for the server.

First to ~/.zshrc add line export LANG="en_US.UTF-8" and to /etc/ssh/ssh_config the following:

Host exampleserver
SendEnv LANG

Reload your shell init file by source ~/.zshrc (I use alias rp for this).

Server configuration

On server side (Ubuntu 16.04 in this case) you need to receive the LANG from the client, which it does by default. In case of problems make sure that the file /etc/ssh/ssh_config has the line AcceptEnv LANG. In this case the default was AcceptEnv LANG LC_*which works fine.

Leave a Reply

Your email address will not be published. Required fields are marked *