linux - iterm 配置utf8编码,本地终端中文不乱码,ssh远程中文乱码,咋整啊
高洛峰
高洛峰 2017-04-17 12:06:30
0
4
988
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(4)
PHPzhong

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

Peter_Zhu

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:

export LANG='UTC-8'
export LC_ALL='en_US.UTF-8'

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.

Ty80

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

LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"

At this time, Chinese input and display are normal.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template