Pages

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:

  1. This helped solve my problem. Thanks!

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

    ReplyDelete
  3. Thank you for helping fix this issue!

    ReplyDelete
  4. Thanks. It works for Mountain Lion as well.

    ReplyDelete
  5. Thanks for writing this up.

    ReplyDelete
  6. 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!

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

      Delete
  7. awesome .. made my day!

    ReplyDelete
  8. Thanks, this fix worked for me.

    ReplyDelete
  9. Thanks, this helped me too.

    ReplyDelete
  10. Thanks a lot! It finally solves this little annoying problem!

    ReplyDelete
  11. Great post. Thanks a lot. :)

    ReplyDelete
  12. Thank you! This has bugged me for months!

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

    Dharmesh Shah

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

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

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

    ReplyDelete
  17. Thanks Grey. Appreciate it.

    ReplyDelete
  18. Thanks for the quick fix!

    ReplyDelete