Mac连接到Linux上,不能输入中文

链接地址:

http://blog.csdn.net/aabbcc456aa/article/details/50681330

 

服务器是ubuntu,用Mac的iterm2 ssh连上去,终端显示中文乱码,也不能输入中文,然而本地终端可以显示和输入。

解决方法:

这种情况一般是终端和服务器的字符集不匹配,MacOSX下默认的是utf8字符集。
输入locale可以查看字符编码设置情况,而我的对应值是空的。
因为我在本地和服务器都用zsh替代了bash,而且使用了oh-my-zsh,而默认的.zshrc没有设置为utf-8编码,所以本地和服务器端都要在.zshrc设置,步骤如下,bash对应.bash_profile.bashrc文件。

1.在终端下输入

1
vim ~/.zshrc

或者使用其他你喜欢的编辑器编辑~/.zshrc文件

2.在文件内容末端添加:

1
2
export LC_ALL=en_US.UTF-8  
export LANG=en_US.UTF-8 

接着重启一下终端,或者输入source ~/.zshrc使设置生效。

设置成功的话,在本地和登录到服务器输入locale回车会显示下面内容。

1
2
3
4
5
6 7 8 
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" 

这时,中文输入和显示都正常了。

3.如果设置之后出现以下问题

-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
解决办法:

1
2
3
sudo locale-gen en_US.UTF-8

sudo dpkg-reconfigure locales

解释:

1
The error "bash: warning: setlocale: LC_ALL: cannot change locale (en_US)" occurs when the remote server does not understand the locale "en_US.UTF-8". The fix is to generate the locale using the command "sudo locale-gen en_US.UTF-8" and update the locale repository to store this locale, such that future connections(ssh) can understand this locale. The command "sudo dpkg-reconfigure locales" updates the local repository with the newly generated locale, i.e en_US.UTF-8. 

(大概意思就是服务器上没有安装这个编码的字符集,安装之后设置一下就支持了)

转载于:https://www.cnblogs.com/qinyan20/p/6225547.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值