Remember the reason why Centos modify the language environment variable $LANG does not take effect

**Question background: **

Edit /etc/locale.conf and change it to LANG="en_US.UTF-8", after restarting the server, enter the system, it still displays Chinese

**Troubleshooting and analysis: (reproduce the problem environment) **
  1. Confirm that the current system supports the en_US.UTF-8 language environment (en_US.utf8 and en_US.UTF-8 have the same effect)
# locale -a | grep en_US
en_US
en_US.iso88591
en_US.iso885915
en_US.utf8                              //English utf8 locale is supported
  1. Confirm the locale in effect of the current system
root@BJ-CentOS7 ~ # echo $LANG
zh_CN.UTF-8//The locale in effect is Chinese utf8
root@BJ-CentOS7 ~ # locale
LANG=zh_CN.UTF-8//The locale in effect is Chinese utf8
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=
  1. Check the current configuration in the system, it is indeed configured in English, and the server has been restarted, the configuration of the environment variable $LANG should take effect, and no related configuration is found in other related configuration files.
root@BJ-CentOS7 ~ # grep LANG /etc/locale.conf 
LANG="en_US.UTF-8"
root@BJ-CentOS7 ~ # grep LANG /etc/profile
root@BJ-CentOS7 ~ # grep LANG ~/.bashrc 
  1. It is found that it works normally under VNC, but the remote connection does not take effect
    The problem is basically clear. The SSH configuration during remote connection passes the current environment variable configuration to the remote host session
    Introduction to SSH configuration file reference: https://www.cnblogs.com/52linux/archive/2012/03/24/2415470.html

It turns out that the SendEnv and AcceptEnv parameters are configured by default in the server as a springboard and the target server to be connected, and the $LANG variable is configured in both the client and the remote host, which causes the environment variables specified in the client environment to take effect in the remote session Up

In the client ssh_config configuration file: The SendEnv parameter is used to define which environment variables are sent to the remote session
In the remote host sshd_config configuration file: The AcceptEnv parameter is used to define which matched environment variables are received

root@BJ-CentOS7 ~ # grep AcceptEnv /etc/ssh/sshd_config 
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
root@BJ-CentOS7 ~ # 
root@BJ-CentOS7 ~ # grep SendEnv /etc/ssh/ssh_config 
 SendEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
 SendEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
 SendEnv LC_IDENTIFICATION LC_ALL LANGUAGE
 SendEnv XMODIFIERS

solution:
  1. Connect to the server directly through the remote tool, will not be affected by the client ssh configuration
  2. Remove the relevant configuration of the $LANG variable transmission in the client or remote host SSH configuration
    ssh_config and sshd_config match the file with the LANG value after the SendEnv and AcceptEnv parameters are removed respectively


Reference documents:
https://www.cnblogs.com/52linux/archive/2012/03/24/2415470.html

Recommended Posts

Remember the reason why Centos modify the language environment variable $LANG does not take effect
Centos7 modify the system language to simplified Chinese