Fixing the Mac OS Umlaut/Keyboard-Layout issue when connecting to remote machines via SSH

When connecting from a Mac with a German keyboard layout using Terminal or iTerm to a remote cloud-machine running Ubuntu you might have issues entering umlaut characters such as äüöß.
created by on 2015-06-21

Mac OS Terminal after enter ö

Screenshot: Mac OS Terminal with Umlaut issue

Mac OS iTerm after entering öü

Screenshot: Mac OS iTerm with Umlaut issue

The reason for this is that cloud instances of Ubuntu will usually have an english keyboard layout (en_US or en_GB) and not the one you are using on your host computer (e.g. de_DE). So every time you think you enter ö you will actually enter :. If you enter ä you will get @. If you enter ü you will get {, and so on …

Illustration: Highlighting the differences between English and German Keyboard Layouts

But I have no idea why this only happens if I connect via Terminal or iTerm on a Mac. I have tested it and it does not happened on a Ubuntu machine, or if you are using Putty on Windows.

Ubuntu's Gnome Terminal does not have problems with the keyboard layout

Putty does not have problems with the keyboard layout

Nevertheless, here is how you can fix the issue for your Mac terminals:

  1. Run locale-gen en_US en_US.UTF-8 de_DE de_DE.UTF-8 (optional)
  2. Run dpkg-reconfigure locales (optional)
  3. Add the line set convert-meta off to your /etc/inputrc file. (required)
  4. Reconnect your ssh session (required)

Exchange de_DE with your locale.

Fixing the SSH Umlaut Issue

From my experience I can say that steps 1 and 2 are even optional, but I would do them anyway to be on the safe side.

Detailed Step-by-Step Guide

The first time you connect to a new Ubuntu machine you usually cannot enter umlaut characters and the welcome message looks something like this:

Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-52-generic x86_64)

 * Documentation:

  System information as of Sat Jun 20 16:09:34 EDT 2015

  System load: 0.0               Memory usage: 9%   Processes:       50
  Usage of /:  7.5% of 19.56GB   Swap usage:   0%   Users logged in: 0

  Graph this data and manage this system at:

WARNING! Your environment specifies an invalid locale.
 This can affect your user experience significantly, including the
 ability to manage packages. You may install the locales by running:

   sudo apt-get install language-pack-UTF-8
   sudo locale-gen UTF-8

To see all available language packs, run:
   apt-cache search "^language-pack-[a-z][a-z]$"
To disable this message for all users, run:
   sudo touch /var/lib/cloud/instance/locale-check.skip

The welcome message gives you a recommendation that you might need to do something to fix problems regarding your locale. But unfortunately the the recommended commands don’t solve the problem:

Using the command from the Ubuntu welcome message does not solve the problem

But if you use locale-gen with different arguments than recommended by the welcome message you are on the right track.

So let’s do it - generate the locales for your language (e.g. de_DE):

locale-gen en_US en_US.UTF-8 de_DE de_DE.UTF-8
Generating locales...
  de_DE.ISO-8859-1... done
  de_DE.UTF-8... done
  en_US.ISO-8859-1... done
  en_US.UTF-8... up-to-date
Generation complete.

Screenshot: Running locale-gen for de_DE

Additionally you can also re-generate your locales afterwards:

dpkg-reconfigure locales
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
		LANGUAGE = (unset),
		LC_ALL = (unset),
		LC_CTYPE = "UTF-8",
		LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Generating locales...
  de_DE.ISO-8859-1... up-to-date
  de_DE.UTF-8... up-to-date
  en_AG.UTF-8... done
  en_AU.UTF-8... done
  en_BW.UTF-8... done
  en_CA.UTF-8... done
  en_DK.UTF-8... done
  en_GB.UTF-8... up-to-date
  en_HK.UTF-8... done
  en_IE.UTF-8... done
  en_IN.UTF-8... done
  en_NG.UTF-8... done
  en_NZ.UTF-8... done
  en_PH.UTF-8... done
  en_SG.UTF-8... done
  en_US.ISO-8859-1... up-to-date
  en_US.UTF-8... up-to-date
  en_ZA.UTF-8... done
  en_ZM.UTF-8... done
  en_ZW.UTF-8... done
Generation complete.

Screenshot: Running dpkg-reconfigure locales

But this alone will not solve the problem. You need to turn off the convert-meta option in your /etc/inputrc:

set convert-meta off

If set to on, Readline will convert characters with the eighth bit set to an ASCII key sequence by stripping the eighth bit and prefixing an ESC character, converting them to a meta-prefixed key sequence. The default value is on.

For more details on convert-meta and /etc/inputrc visit this site: Beyond Linux From Scratch - /etc/inputrc

The first three lines of your /etc/inputrc should look like this:

# Be 8 bit clean.
set input-meta on
set output-meta on
set convert-meta off

Screenshot: /etc/inputrc after adding set convert-meta off

Close your SSH connection and reconnect. Now you should be able to enter umlaut characters from your Mac Terminal.

Fork allmark on GitHub