Fixing Cygwin Unicode issues

Published: 7 years ago web dev

Recently I noticed I've not been able to paste Unicode characters into an ssh session when using Cygwin. Pasting them into the terminal locally worked fine. Here follows how to determine the issue and the simple solution.

The problem in my case was that the Cygwin ssh client was not sending the language environmental variables when connecting to the ssh server. You can determine what your language environmental variables are set to by running locale. Here is what my locale looked like on a local Cygwin session:

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

These settings are fed through to the terminal from the options (go to Options > Text to set the locale and character set). However when ssh'ing into a remote machine the locale looked like this:

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 fix this you just need to edit the local /etc/ssh_config file (you may need to be using Cygwin with elevated permissions to edit this file) and add:

SendEnv LANG LC_*

You also need to ensure the sshd_config on the remote machine accepts the client setting the language variables:

$ cat /etc/ssh/sshd_config | grep -i accept
AcceptEnv LANG LC_*

Note that you need to have the language installed on the remote machine. You can see all your installed locales via locale -a.

Other options to fix this issue are listed on this Ask Ubuntu answer. Setting the language variables in .bash_profile may make most sense.