The server is ubuntu, and I use Mac’s iterm2 ssh to connect to it. The terminal displays garbled Chinese characters and cannot input Chinese, but the local terminal can display and input.
Solution:
This situation is usually caused by the character set mismatch between the terminal and the server. The default character set under MacOSX is utf8. Enter locale to view the character encoding settings, but my corresponding value is empty. Because I replaced zsh with bash both locally and on the server, and used oh-my-zsh, and the default .zshrc is not set to utf-8 encoding, so both the local and server sides must be in .zshrc Settings, the steps are as follows, bash corresponds to .bash_profile or .bashrc files.
1. Enter
in the terminal
vim ~/.zshrc
Or use your favorite editor to edit the ~/.zshrc file <!--more-->
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.
If the setting is successful, enter locale and press Enter locally and when logging in to the server, the following content will be displayed.
Edit the ~/.vimrc file and add the following lines:
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
http://blog.icodu.com/?p=560
I encountered the same problem, mainly because the language encoding of the remote server was inconsistent with the encoding of the terminal.
Add the following code to the ~/.bashrc file on the remote server:
Then bash it and the Chinese will be displayed normally.
The .bashrc file will run automatically next time you log in, and Chinese will still be displayed normally.
The reason why the encoding of remote terminal and local terminal does not match
Question:
The server is ubuntu, and I use Mac’s iterm2 ssh to connect to it. The terminal displays garbled Chinese characters and cannot input Chinese, but the local terminal can display and input.
Solution:
This situation is usually caused by the character set mismatch between the terminal and the server. The default character set under MacOSX is utf8.
Enter
locale
to view the character encoding settings, but my corresponding value is empty.Because I replaced
zsh
withbash
both locally and on the server, and usedoh-my-zsh
, and the default.zshrc
is not set toutf-8
encoding, so both the local and server sides must be in.zshrc
Settings, the steps are as follows, bash corresponds to.bash_profile
or.bashrc
files.1. Enter
in the terminalOr use your favorite editor to edit the
~/.zshrc
file<!--more-->
2. Add:
at the end of the file contentThen restart the terminal, or enter
source ~/.zshrc
to make the settings take effect.If the setting is successful, enter
locale
and press Enter locally and when logging in to the server, the following content will be displayed.At this time, Chinese input and display are normal.