iTerm2 connection remote, Chinese garbled

The iterm2 terminal is used on the mac, and the shell environment is zsh. When I ssh to the Linux server to view some files, the Chinese characters are garbled. In this case, the character set of the terminal and the server do not match, and the default is utf8 character set under MacOSX.

The solution is as follows:
Enter locale to check the character encoding settings, and my corresponding value is empty. The default .zshrc is not set to utf-8 encoding, so the local and server sides must be set in .zshrc, the steps are as follows, (bash corresponds to the .bash_profile or .bashrc file).

1. Enter
vim ~/.zshrc

in the terminal

2. Add at the end of the file content:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

Then restart the terminal, or enter source ~/.zshrc to make the settings take effect. Connecting to the server, the Chinese display is normal.

Leave a Comment

Your email address will not be published.