Mac Terminal Doesn't display Unicode UTF-8 Properly when ssh'ed into Linux and running Emacs

10,244

The remote host doesn’t know that your terminal is using UTF-8.

By default, Terminal encodes text as UTF-8, and by default Terminal communicates this to the terminal shell via the LANG environment variable (as long as you haven’t changed these preference settings).

You can see the encoding (and language) being used with the command locale. For example, this is what it says on my Mac:

$ locale
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=

If you run it locally and on the remote host you should see that the remote host doesn’t include “utf-8” in the locale values.

However, prior to Mac OS X Lion 10.7, by default ssh doesn’t communicate the LANG environment variable to the remote host. You can arrange for this, but it requires configuring both the ssh client on your Mac to send the LANG variable and the sshd daemon on the remote host to read it.

See the ssh_config and sshd_config man pages on the Mac and the remote host for details. You will probably add a line like SendEnv LANG LC_* to the /etc/ssh/ssh_config file on your Mac and AcceptEnv LANG LC_* in /etc/ssh/sshd_config on the remote host (the details may vary on the remote host).

Alternatively, you can simply export LANG="en_US.UTF-8" once you log in to the remote shell (the exact syntax depends on the remote shell you’re using). Be sure to use the correct language if it isn’t US English (“en_US”). You may also automate this by setting LANG from within a shell startup script like ~/.bash_profile on the remote host.

Share:
10,244

Related videos on Youtube

vy32
Author by

vy32

I love programming and have been doing it since 1972.

Updated on September 18, 2022

Comments

  • vy32
    vy32 over 1 year

    I am logged into a Mac, running Terminal, ssh'ed into a Linux system and running make in an emacs window. My error log looks like this:

    _raw.cpp:139: error: invalid conversion from âconst char*â to âsize_tâ
    _raw.cpp:139: error:   initializing argument 2 of âint snprintf(char*, size_t, const char*, ...)â
    _raw.cpp:139: error: invalid conversion from âintâ to âconst char*â
    _raw.cpp:139: error:   initializing argument 3 of âint snprintf(char*, size_t, const char*, ...)â
    

    Notice that apparently GCC is trying to use the unicode smartquote characters, but they are being sent as UTF-8 and Emacs is intercepting them. I think that the problem here is that EMACS needs to pass the UTF-8 generated by the subprocess through to the Terminal. Any idea how to make that happen?