Iterm2登录远程终端中文乱码显示

用iterm2登录到服务器后显示如下告警,同时看到中文都用问号显示了

$ ssh dn03
Last login: Tue Oct 17 09:24:20 2023 from 192.168.3.98
-bash: 警告:setlocale: LC_CTYPE: 无法改变区域选项 (UTF-8): 没有那个文件或目录
[root@dn03 ~]# ls
(7).xlsx             hs_err_pid23184.log  hs_err_pid4487.log   hs_err_pid51754.log  hs_err_pid9111.log    temp         ??????
anaconda-ks.cfg      hs_err_pid31987.log  hs_err_pid47317.log  hs_err_pid54396.log  hs_err_pid9361.log    yitihua.out  ??????
data                 hs_err_pid32534.log  hs_err_pid48324.log  hs_err_pid55513.log  http:                 ??????       ??????
hs_err_pid16867.log  hs_err_pid36537.log  hs_err_pid49625.log  hs_err_pid6194.log   initial-setup-ks.cfg  ??????       ??????
hs_err_pid18668.log  hs_err_pid37369.log  hs_err_pid49762.log  hs_err_pid8732.log   logs                  ??????       ??????
[root@dn03 ~]# 

原因

The character set of the terminal and the server does not match. The default is utf8 character set under MacOSX.

方案

  1. 打开本地配置文件,我用的oh-my-zsh,所以修改如下配置
vim ~/.zshrc
  1. 添加下面的内容到文件中
export LC_ALL=en_US.UTF-8  
export LANG=en_US.UTF-8
  1. 重启iterm,或者使用下面的命令使其生效
source ~/.zshrc

查验效果

# mahaiqiang @ mahaiqiangdeAir in ~ [12:31:12]
$ vim ~/.zshrc

# mahaiqiang @ mahaiqiangdeAir in ~ [12:31:20]
$ source ~/.zshrc

# mahaiqiang @ mahaiqiangdeAir in ~ [12:31:24]
$ ssh dn03
Last login: Tue Oct 17 12:29:23 2023 from 192.168.3.98
[root@dn03 ~]# ls
(7).xlsx             hs_err_pid23184.log  hs_err_pid4487.log   hs_err_pid51754.log  hs_err_pid9111.log    temp         文档
anaconda-ks.cfg      hs_err_pid31987.log  hs_err_pid47317.log  hs_err_pid54396.log  hs_err_pid9361.log    yitihua.out  桌面
data                 hs_err_pid32534.log  hs_err_pid48324.log  hs_err_pid55513.log  http:                 下载         模板
hs_err_pid16867.log  hs_err_pid36537.log  hs_err_pid49625.log  hs_err_pid6194.log   initial-setup-ks.cfg  公共         视频
hs_err_pid18668.log  hs_err_pid37369.log  hs_err_pid49762.log  hs_err_pid8732.log   logs                  图片         音乐
[root@dn03 ~]#
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容