-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8)

Fixing the LC_CTYPE: cannot change locale (UTF-8) error on CentOS

If you’ve recently upgraded to CentOS 6.3 you might have seen the following error message after logging in to your system via SSH:

-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8)

Although it’s easy to asume the problem must be on the server-side (and in a part it is), but you actually have to fix an ssh_config setting on your local system.

SSH sends LC_* environment variables

The problem is that your SSH client is by default configured to send your LC_* environment variables. This means that SSH will try to set every LC_* variable you have set on your local (connecting) system on the remove system as well. The problem is that since CentOS 6.3 the name of the locale is not compatible with what some SSH clients (like the default OpenSSH client on Apple Mac OSx) has set. Let’s take a closer look:

Locale setting on local system

When you run:

printenv

you see which LC_* variables are set locally. On my Mac OSx Mountain Lion system it prints:

LC_TYPE=UTF-8

Locales available on the remote CentOS system

If you enter:

locale -a

you get a list of locales which you have available on your CentOS system. The locale you have set on your local system (“UTF-8″ in my case) should also be present here. When grep’ing the list:

locale -a | grep  ”UTF-8″

it quickly becomes clear that my the locale setting on my locale (Mac OSx) system is not available on the remote CentOS system.

Preventing OpenSSH from sending the LC_* variables

The fix is very easy. On your local system open your ssh_config file as root (usually in /etc/ssh_config or /etc/sshd/ssh_config) and comment this line:

SendEnv LANG LC_*

That’s it! From now on you will no longer get the annoying Bash error. Alternatively you can also set the locale setting of your locale system to something that matches your remote system, but this is the foolproof way that will always work, regardless of the locale config of your local and remote system.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值