The Problem
Mosh (mobile shell) is the perfect choice for roaming SSH sessions. Log in at home, work on the train, wake the laptop from sleep at the office and find the session still alive. It feels like magic.
There's one snag: Mosh requires UTF-8 on both client and server. Modern clients are fine, but servers can be another story. I regularly work with legacy servers still running ISO-8859-1. Accessing them with UTF-8 is awkward — we Swedes need our beloved åäö, and the encoding mismatch turns them into garbage.
The Solution
Enter luit. It runs as a filter between an application and the terminal, translating between UTF-8 and the application's encoding. Set it up as a filter for the login shell, and it transparently handles the entire session.
On the server, add this as the last line of .bash_profile:
LC_ALL='' LC_CTYPE=sv_SE LANG='' exec luit
Adjust the locale variables to match your needs.
The Trap
Warning: Do NOT put this in
.bashrc, and make sure.bashrcand.bash_profileare not symlinked to the same file.
Here's why: exec luit starts an interactive shell, which sources .bashrc, which runs exec luit, which starts an interactive shell… Your login never completes, and the server fills up with thousands of luit processes — an effective fork bomb.
Installing luit
Luit might already be installed. If not:
# Debian / Ubuntu
sudo apt-get install x11-utils
# RHEL / CentOS
sudo yum install xorg-x11-utils
After that, mosh user@legacy-server just works. Full åäö support, roaming sessions, and no encoding headaches.