Mac – sshd not setting locale

macportssshutf-8

Edit: I should have mentioned in my original question that I was using MacPorts SSH client, as it turned out there were two root causes. See my own answer below.

When I SSH into my OSX machine, it's not setting the locale properly:

LANG=
LC_COLLATE="C"
LC_CTYPE="C"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

This should be using a UTF-8 locale. It should look like this:

LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL=

I'm running OSX 10.11.6 (El Capitan), and I've enabled the SSH server in System Preferences.

I'm using putty as a client on my Windows machine. When I use the same putty configuration to connect to a Linux server, the locale information is fine.

When I run a local terminal on the OSX machine, locale is fine. If I then ssh localhost, I have the same problem: no locale is set.

It seems that my OSX SSH server is ignoring or discarding the locale information from the client. I have the following in my (unmodified) /etc/ssh/sshd_config:

AcceptEnv LANG LC_*

To the best of my knowledge, that's all that's required.

My putty configuration is sending TERM=xterm-256color, which is being honored; it's only the locale information that isn't working, and to reiterate, it happens when I ssh localhost from OSX to itself, so I don't think putty is the issue here.

I will not accept answers that suggest setting the locale in my .profile; there are plenty of answers on here suggesting that, but it's a hack, not a solution.

Best Answer

Turns out there were two problems here:

First, PuTTY wasn't actually sending any locale information. Apparently the Linux servers were configuring the locale automatically, or based on TERM or something. I fixed PuTTY by configuring environment variables for it to send:

PuTTY locale configuration

Second, I'm using MacPorts (updated question since this was missing in the original), and MacPorts ssh does not send locale variables. I can't imagine why MacPorts configures SSH this way, but I had to add the following to /opt/local/etc/ssh/ssh_config:

Host *
  SendEnv LANG LC_*

That really ought to be the default MacPorts config; it's the default on any standard Linux system, and it's even the default in OSX's own SSH. Figured out that MacPorts was part of the problem when SSH from Linux to OSX did set the locale.

I've filed a ticket with MacPorts suggesting the default be changed.