This topic describes how to resolve the issue that the Chinese characters on a Linux Elastic Compute Service (ECS) instance are garbled.
Problem description
When you connect to a Linux ECS instance by using a third-party SSH client, the Chinese characters on the instance are garbled.
Causes
The issue may occur because of the following reasons:
Chinese fonts are not installed on the Linux operating system. By default, Linux does not support Chinese characters to be displayed. You must install a Chinese language pack to allow Chinese characters to be displayed on Linux. To resolve the issue, perform the operations that are described in the Solution 1: Install a Chinese language pack on Linux section.
The character set of the third-party SSH client tool is incorrectly configured. To resolve the issue, perform the operations that are described in the Solution 2: Modify the character set of the third-party SSH client tool section.
Solutions
Use one of the following solutions to resolve the issue based on the actual scenario:
Solution 1: Install a Chinese language pack on the Linux ECS instance
In this example, an instance that runs CentOS 7.8 is used. Configurations and commands may vary based on operating systems, such as other CentOS versions and other distributions such as Red Hat, Debian, and Ubuntu. For more information, see the official documentation of these operating systems.
CentOS 6 and CentOS 8 have reached their end of life (EOL). In accordance with Linux community rules, all content has been removed from the CentOS 6 and CentOS 8 repository addresses. If you continue to use the default repository address of CentOS 6 or CentOS 8, an error is reported. We recommend that you change the repository address of CentOS 6 or CentOS 8. For more information, see Change the CentOS 6 source address and Change CentOS 8 repository addresses .
Connect to the Linux instance.
For more information, see Connect to a Windows instance by using a password or key.
Run the following command to query the language that is used by the operating system:
echo $LANG
NoteIf English is used, proceed to Step 3.
If Chinese is used, a Chinese language pack is installed on the Linux operating system. In this case, the garbled Chinese characters are not caused by non-installed Chinese fonts. To resolve the issue, perform the operations that are described in the Solution 2: Modify the character set of the third-party SSH client tool section.
Run the following command to check whether a Chinese language pack is installed on the operating system:
locale -a | grep "zh_CN"
A command output similar to the following one is displayed. zh indicates Chinese, CN indicates China, and gb18030, gb2312, gbk, and utf8 are character sets.
zh_CN zh_CN.gb18030 zh_CN.gb2312 zh_CN.gbk zh_CN.utf8
If a Chinese language pack is not installed, run the following command to install it:
sudo yum groupinstall "fonts"
Run the following command to edit the
/etc/locale.conf
configuration file:vim /etc/locale.conf
Press the
i
key to enter the edit mode. ChangeLANG=en_US.UTF-8
toLANG=zh_CN.UTF-8
to change the system language to Chinese.After the modification is complete, press the
Esc
key, enter:wq
, and then press the Enter key to save and close the configuration file.
Run the following command for the configuration to take effect:
source /etc/locale.conf
Run the following command to restart the instance:
reboot
(Optional) If the system language is still English after the instance is restarted, run the following command to edit the
/etc/profile.d/lang.sh
configuration file:vim /etc/profile.d/lang.sh
Press the
i
key to enter the edit mode and changezh*) LANG=en_US.UTF-8
tozh*) LANG=zh_CN.UTF-8
. The following figure shows the modified content.After the modification is complete, press the
Esc
key, enter:wq
, and then press the Enter key to save and close the configuration file.Run the following command to restart the instance:
reboot
Solution 2: Modify the character set of the third-party SSH client tool
The following section describes how to modify the character set of a Xshell client tool.
Start the Xshell client.
In the Xshell client window, set Default Language to Unicode (UTF-8).
Log on to the instance again and check whether the Chinese fonts are displayed as expected.