6

I have setup a fresh Ubuntu 16.04 server, but when I attempt to permanently change the locale settings, it fails and reverts back to the POSIX locale.

Typing locale yields the following:

LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=

To my knowledge, this means that no locale has been set at all, as the documentation states POSIX is the "fall-back, ASCII encoding, same as C".

To ensure the locales de_AT.utf8 and en_US.utf8 were present on my system, I ran locale -a, which yielded:

C
C.UTF-8
POSIX
de_AT.utf8
en_AG
en_AG.utf8
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IN
en_IN.utf8
en_NG
en_NG.utf8
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.utf8
en_ZA.utf8
en_ZM
en_ZM.utf8
en_ZW.utf8

Please note the inconsistencies with C.UTF-8, but de_AT.utf8! What further worries me is that POSIX is the third entry, while on a different, working system, it's last of the list.

In order to change my language to en_US.utf8, I typed sudo update-locale LANG=en_US.utf8. The locale command still showed the POSIX locale. After a logout and new login, locale still showed the POSIX locale. After a reboot, locale still showed the POSIX locale.

However, when I type export LANG=en_US.utf8, it works temporarily, but only until logout. As such, I am pretty certain that the locales were generated correctly.

I am out of ideas. I tried regenerating all locales, but it looks as if /etc/default/locale is simply being ignored.

For the sake of completion, /etc/default/locale only contains the line LANG=en_US.utf8

UPDATE:// I tried running sudo localectl set-locale LANG=en_US.UTF-8, and localectl also showed me that it set the locale, but even after a reboot, locale still shows POSIX and non-ASCII characters are still not rendered correctly.

  • 1
    /etc/default/locale is read by PAM. Did you possibly disable PAM? – Gunnar Hjalmarsson May 10 '16 at 15:16
  • Did you try systemd way : localectl set-locale LANG=C.UTF-8 ? – EdiD May 10 '16 at 15:54
  • @GunnarHjalmarsson Not that I would be aware of. How can I check? – MechMK1 May 10 '16 at 16:34
  • @EdiD I tried, rebooted, but no change – MechMK1 May 10 '16 at 16:35
  • Not sure. PAM should be enabled on a fresh install, and if you haven't changed anything in /etc/pam.d, it should work. But as a hack for now you may want to create /etc/profile.d/mylocalesetting.sh and add the line export LANG=en_US.UTF-8. – Gunnar Hjalmarsson May 10 '16 at 17:12
7

The answer was indeed PAM-related, as Gunnar Hjalmarsson mentioned in a comment. PAM was disabled via sshd_config, although I honestly do not remember doing so myself.

To summarize: If /etc/default/locale seems being ignored, check if PAM is enabled.

6

Run the following commands:

locale-gen en_US.UTF-8
dpkg-reconfigure locale
dpkg-reconfigure keyboard-configuration
localedef -i en_US -c -f UTF-8 en_US.UTF-8
reboot
locale
  • Didn't work. locale still shows POSIX for everything – MechMK1 May 10 '16 at 15:12
  • I assume you have been root for running those commands? I'm not trying to offend, just want to be sure. – Videonauth May 10 '16 at 15:15
  • Yeah, of course. There were no error messages or anything similar. – MechMK1 May 10 '16 at 15:22
  • 1
    did you mean locales? – realtebo Jul 13 '16 at 11:20
  • I'm doing this and it seems to be "dpkg-reconfigure locales" then everything will work. – Hugo Jul 30 '16 at 12:51
6

What I eventually did is a combination of above techniques

I've first done

dpkg-reconfigure locales

and chosed english, utf8, then:

localedef -i en_US -c -f UTF-8 en_US.UTF-8

Also edited /etc/default/locale to look like:

LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8
LANGUAGE=en_US.UTF-8

And after reboot, when I type locale it now looks like this:

LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8

And no more warnings...

0

In deploying some new 16.04.5 VMs, I ran into this exact problem, but with xrdp instead of SSH. I solved this by adding the following to /etc/pam.d/common-session:

session required        pam_env.so readenv=1 user_readenv=1 envfile=/etc/default/locale

If you are sensitive to additional languages and cultures across login methods, you could put this in /etc/pam.d/xrdp-sesman (or another PAM configuration file) instead. This may be why it isn't there by default? This is in the following PAM configurations by default on our new VM installations:

cron, lightdm*, login, polkit-1, sshd, su, and sudo.

Hope this helps someone with this problem given login methods other than SSH.

Does anyone know best practices for PAM configuration/modification of common-*? If there's a better way to get this going it would be good to get that down.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.