iterm2连接linux乱码问题
本人使用的是MBP,然后终端使用iTerm2 + oh My Zsh。
Linux服务器所使用的是系统是CentOS Linux release 7.5.1804。
早上通过终端登陆Linux服务器的时候,发现上面的中文显示的全都是???,如图1所示
![](https://upload-images.jianshu.io/upload_images/3909412-a3710e21f13ec083.png?imageMogr2/auto-orient/strip|imageView2/2/w/353/format/webp)
图1
这就很尴尬了,于是开始排查原因,首先想到的就是Linux系统中的locale,是不是系统的字符集设置错了?于是立马查看locale,如图2所示
![](https://upload-images.jianshu.io/upload_images/3909412-5de65c17db1a53db.png?imageMogr2/auto-orient/strip|imageView2/2/w/587/format/webp)
图2
发现系统的编码本身也是没问题的。于是怀疑是iTerm2的问题,导致显示有问题,于是打开终端连接设置,查看编码格式,如图3所示
![](https://upload-images.jianshu.io/upload_images/3909412-b547cedf18d441aa.png?imageMogr2/auto-orient/strip|imageView2/2/w/582/format/webp)
图3
发现连接也是用的UTF-8,没什么问题,最后怀疑是bash连接的问题,于是在linux系统中的【~/.bashrc】中加入
export LC_ALL=zh_CN.UTF-8 export LANG=zh_CN.UTF-8
如图4所示
![](https://upload-images.jianshu.io/upload_images/3909412-638d57302a80597e.png?imageMogr2/auto-orient/strip|imageView2/2/w/326/format/webp)
图4
关闭终端连接,重新开启连接,发现显示已经恢复正常,如图5
![](https://upload-images.jianshu.io/upload_images/3909412-a31462542b4aa5bb.png?imageMogr2/auto-orient/strip|imageView2/2/w/412/format/webp)
图5