Johan Ekenberg

Computer Programmer and Double Bass Player

Mosh+luit: Mobile Shell on ISO-8859-1

Mosh + luit solves the UTF-8 / ISO-8859-1 problem.

Mosh (mobile shell) is the perfect choice for roaming ssh sessions. Login at home, work on the train, wake the laptop from sleep when arriving at work and find the ssh session still active. It feels almost like magic. I use it all the time. There is however one snag: Mosh requires UTF-8 on both client and server. For modern clients, this is not a problem, but servers can be another story. I regularly work with legacy servers still on ISO-8859-1. Accessing them with UTF-8 is awkward: we Swedes need our beloved ‘åäö’, and UTF-8 <-> ISO-8859-1 will mess up non-ascii characters.

Enter luit. Luit runs as a filter between an application and the terminal, translating between UTF-8 and the application encoding. That means luit can transparently filter the entire terminal session if setup as a filter for the login shell. On the server, I put this as the last line of my .bash_profile (adjust locale environment variables according to your needs):

Last line of .bash_profile
LC_ALL='' LC_CTYPE=sv_SE LANG='' exec luit

Warning: Don’t put it in .bashrc, and make sure your .bashrc and .bash_profile are not symlinked to the same file! exec luit starts an interactive shell which invokes .bashrc which does exec luit which starts an interactive shell… Your login will never complete, and the server will fill up with thousands of luit processes, an effective fork bomb.

Luit might already be installed on your server. If not, it should be available through your packet manager. On any Debian derived system (Ubuntu etc): sudo apt-get install x11-utils