SSH 登录出现 LC_CTYPE 错误

好风 发表于 2018-07-03T13:14:50.049455Z
引用地址:https://plus.ooclab.com/note/article/1412

从 MacOS iTerm2 登录 CentOS 7 SSH Server , 出现如下错误:

-bash: 警告:setlocale: LC_CTYPE: 无法改变区域选项 (UTF-8): 没有那个文件或目录

查看出错时的 locale :

[root@ooclab-t10 ~]# locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: ?????????
LANG=zh_CN.UTF-8
LC_CTYPE=UTF-8
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=

发现 LC_CTYPE 的名称不在 locale -a 中,即名称不合法。

参考 Cannot set LC_CTYPE to default locale: No such file or directory

This same problem (LC_CTYPE=UTF-8, which is wrong) can happen when you login over ssh from a Mac to a linux box, and your terminal automatically sets environment variables. There's a checkbox for that. Uncheck it, and you're good to go. In iTerm it's in the profile->Terminal Tab.

/etc/locale.conf 增加 LC_CTYPE="zh_CN.UTF-8" 解决问题。