AdSense Mobile Ad

Sunday, February 5, 2012

Fixing Mac OS X Lion's SSH UTF-8 Issues

After switching from Mac OS X v. 10.6 (Snow Leopard) to OS X v. 10.7 (Lion), I began experiencing some weird locale-related problems when using OS X as an SSH client. The issues I experienced include, amongst others:
  • Having the terminal complain about invalid locale settings:

$ locale
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 
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE=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=

  • Being unable to correctly type some characters (such as accented characters).
  • Having programs that tunnel their traffic over SSH, such as Subversion, complain about invalid locale settings during their operations:

$ svn co svn+ssh://user@repository/path
svnserve: warning: cannot set LC_CTYPE locale
svnserve: warning: environment variable LC_CTYPE is UTF-8
svnserve: warning: please check that your locale name is correct
svnserve: warning: cannot set LC_CTYPE locale
svnserve: warning: environment variable LC_CTYPE is UTF-8
svnserve: warning: please check that your locale name is correct


In fact, if you look for example at the output of the locale command seen previously, you can see how the LC_CTYPE variable is set UTF-8 while all other LC_* variables (excluding the empty LC_ALL), are set to en_US.UTF-8 (which are correct according to that server settings).

What is the SSH client shipped with Lion doing? Apparently sending incorrect values to the server. It's not just a nuisance having to fix them after logging in, provided you're able to do so: this behaviour is breaking other programs tunnelling their traffic over SSH, such as Subversion, that aren't establishing an interactive SSH tunnel for the user.

Fortunately, the fix is quick: just tell the SSH client not to send any LC_* variable:
  • Open the SSH client configuration file (/etc/ssh_config).
  • Comment out the line that instructs the SSH client to send those variables (SendEnv LANG LC_*) from the general host configuration section (Host *). You should end up with the following fragment:

Host *
# SendEnv LANG LC_*

The configuration change will be immediately applied to any SSH session opened from now on.

Hope this helps.

35 comments:

kiran said...

Thanks for the help :)

Enrico M. Crisostomo said...

You're welcome. ;)

Anonymous said...

Many thanks

Enrico M. Crisostomo said...

You're welcome, I'm glad it helped.

Anonymous said...

This helped solve my problem. Thanks!

Anonymous said...

wow, finally correct characters in ssh screen irssi session! thanks

Enrico M. Crisostomo said...

You're welcome.

Unknown said...

Thank you for helping fix this issue!

Anonymous said...

Thanks. It works for Mountain Lion as well.

Enrico M. Crisostomo said...

Tom, you're welcome.

Enrico M. Crisostomo said...

You're welcome, thanks for the report.

Anonymous said...

Thanks for writing this up.

Enrico M. Crisostomo said...

You're welcome, I'm glad it helped.

Unknown said...

Wow! I didn't expect to find such a precise solution when I googled "Mac LC_CTYPE polluting SSH." Now I have to go and delete all the /etc/default/locale files I've created on my servers.

Talk about a subtle root cause!

Enrico M. Crisostomo said...

Hi Kevin, you're welcome, and I'm really glad this post helped you!

basti schubert said...

awesome .. made my day!

Enrico M. Crisostomo said...

You're welcome, I'm glad it helped!

Anonymous said...

Thanks, this fix worked for me.

Anonymous said...

Thanks, this helped me too.

Enrico M. Crisostomo said...

You're welcome! Glad it helped.

Enrico M. Crisostomo said...

Nice to hear that, I'm glad it helped you!

Leo Fang said...

Thanks a lot! It finally solves this little annoying problem!

Lalo said...

Great post. Thanks a lot. :)

Dennis said...

Thank you! This has bugged me for months!

Enrico M. Crisostomo said...

You're welcome Dennis.

Enrico M. Crisostomo said...

You're welcome Lalo.

Enrico M. Crisostomo said...

I'm glad it helped you, Leo.

Anonymous said...

Thanks, it works on Mavericks 10.9.3 terminal.app ssh-ing into Linux RHEL 6.4 too

Dharmesh Shah

Anonymous said...

Finally, a solution to my problems. Irssi will be fun again. Thank yu!

Anonymous said...

Thanks!

Anonymous said...

First post is from 2012 and it still helped today!
Thanks!

Anonymous said...

Aaaaaah! *That* was it!!!!! A million thanks.

Prasad said...

Thanks Grey. Appreciate it.

Anonymous said...

+1

Rumesh said...

Thanks for the quick fix!