大网数据广告活动
服务器运维问答

Strange set locale behaviour when ssh from Windows PuTTY to Linux

· 52CE 我爱测

Please, can someone shed some light on this strange locales related warning annoying me since I installed my server half year ago. It's a variant of "Cannot set LC_CTYPE to default locale", which seems to be a pretty common issue…

问题原文

原帖链接 · Espinosa · CC BY-SA 4.0

Please,
can someone shed some light on this strange locales related warning annoying me since I installed my server half year ago. It's a variant of "Cannot set LC_CTYPE to default locale", which seems to be a pretty common issue, but mine has a strange twist, not matching any of the cases I found previously reported.

This warning is printed immediately after I log in with PuTTY on Windows to my Linux server.

-bash: warning: setlocale: LC_CTYPE: cannot change locale (en_GB.UTF-8,LANG=en_US.UTF-8): No such file or directory
-bash: warning: setlocale: LC_CTYPE: cannot change locale (en_GB.UTF-8,LANG=en_US.UTF-8)

Same happens when I use ssh command from Git Bash. When I log using VNC and open Konsole in KDE, Bash opens without any of these warnings.

What is unique to my case is the value it tries to set LC_CTYPE: en_GB.UTF-8,LANG=en_US.UTF-8. It looks like two concatenated strings. How this happened!?

This is original output on server side

$ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_GB.UTF-8
LC_CTYPE=en_GB.UTF-8,LANG=en_US.UTF-8
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
...
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=

Note that:
1) all variables are set except LC_ALL - is that normal?
2) LC_CTYPE has the strange "concatenated" value
3) All values has quotes around except LC_CTYPE
4) warning is similar but complaining also about LC_ALL

I tried to fix it by editing ~/.profile, on the server side, by appending:

export LANG=en_GB.UTF-8
export LC_ALL=en_GB.UTF-8

Now, after re-logging, the locale seems to show reasonable values and no warnings from locale command:

$ locale
LANG=en_GB.UTF-8
LC_CTYPE="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
...
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=en_GB.UTF-8

Should I worry about some values not having quotes around them?

But the login warning is still there, still pulling en_GB.UTF8,LANG=en_US.UTF-8 from somewhere:

-bash: warning: setlocale: LC_CTYPE: cannot change locale (en_GB.UTF8,LANG=en_US.UTF-8): No such file or directory
-bash: warning: setlocale: LC_CTYPE: cannot change locale (en_GB.UTF8,LANG=en_US.UTF-8)

Linux server: "openSUSE Leap 15.0"
Windows client 1: PuTTY 0.70
Windows client 2: Git Bash 2.21.0 (MinTTY terminal)

Any ideas?


已采纳解答

原帖链接 · Espinosa · CC BY-SA 4.0

Solved, end of mystery. Problem was in file /etc/locale.conf. It had just one strange line:

LC_CTYPE=en_GB.UTF-8,LANG=en_US.UTF-8

When I changed it to:

LC_CTYPE=en_GB.UTF-8
LANG=en_US.UTF-8

..warning disappeared!

Looks like openSUSE bug; most likely some system upgrade screwed this file, turned line end to a comma. I got a good help on this openSUSE forum.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-03-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。