All Products
Search
Document Center

:What do I do if the Chinese characters on a Linux ECS instance are garbled?

Last Updated:Mar 29, 2023

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:

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.

Note

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 .

  1. Connect to the Linux instance.

    For more information, see Connect to a Windows instance by using a password or key.

  2. Run the following command to query the language that is used by the operating system:

    echo $LANG
    Note
    • If 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.

  3. 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"
  4. Run the following command to edit the /etc/locale.conf configuration file:

    vim /etc/locale.conf
    1. Press the i key to enter the edit mode. Change LANG=en_US.UTF-8 to LANG=zh_CN.UTF-8 to change the system language to Chinese.

    2. After the modification is complete, press the Esc key, enter :wq, and then press the Enter key to save and close the configuration file.

  5. Run the following command for the configuration to take effect:

    source /etc/locale.conf
  6. Run the following command to restart the instance:

    reboot
  7. (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
    1. Press the i key to enter the edit mode and change zh*) LANG=en_US.UTF-8 to zh*) LANG=zh_CN.UTF-8. The following figure shows the modified content. Dingtalk_20210709104253.jpg

    2. After the modification is complete, press the Esc key, enter :wq, and then press the Enter key to save and close the configuration file.

    3. 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.

  1. Start the Xshell client.

  2. In the Xshell client window, set Default Language to Unicode (UTF-8).

  3. Log on to the instance again and check whether the Chinese fonts are displayed as expected.