Locale 环境变量设置不生效

arj*_*jan 7 debian environment-variables locale

我有一个 Debian 6(64 位)VPS,我似乎无法设置语言环境环境变量 LANG 和 LC_*。(以下所有内容均以 root 身份)。

vps:~# locale -a
C
POSIX
en_US.utf8
nl_NL.utf8

vps:~# locale
LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=

vps:~# cat /etc/default/locale
#  File generated by update-locale
LANG=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LC_COLLATE=POSIX
Run Code Online (Sandbox Code Playgroud)

这应该覆盖通过我的 SSH 客户端提供的语言环境设置,但默认语言环境设置不起作用。

.profile、.bashrc、/etc/environment 和 /etc/profile 不包含任何区域设置。我也没有找到这些环境变量来源的任何其他位置。

me:~# grep "LANG" ~/.profile ~/.bashrc /etc/environment /etc/profile
me:~# grep "LC_" ~/.profile ~/.bashrc /etc/environment /etc/profile
me:~#
Run Code Online (Sandbox Code Playgroud)

我的 SSH 客户端设置也没有生效,而它们在其他 VPS 上生效。在本地,我的 /etc/ssh/ssh_config 中有:

SendEnv LANG LC_*
Run Code Online (Sandbox Code Playgroud)

在 VPS 上,/etc/ssh/sshd_config 包含:

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
Run Code Online (Sandbox Code Playgroud)

我不确定变量是否需要生效,但我的 VPS 的 /etc/pam.d/login 包含:

# locale variables are also kept into /etc/default/locale in etch
# reading this file *in addition to /etc/environment* does not hurt
session       required   pam_env.so readenv=1 envfile=/etc/default/locale
Run Code Online (Sandbox Code Playgroud)

并且 /etc/pam.d/sshd 包含:

# Read environment variables from /etc/environment and
# /etc/security/pam_env.conf.
auth       required     pam_env.so # [1]
# In Debian 4.0 (etch), locale-related environment variables were moved to
# /etc/default/locale, so read that as well.
auth       required     pam_env.so envfile=/etc/default/locale
Run Code Online (Sandbox Code Playgroud)

(我/etc/security/pam_env.conf只包含评论选项)

所以,似乎有些东西不允许我的 /etc/default/locale 或我的 SSH 客户端的语言环境设置生效,所以它默认为 POSIX(或者某些东西明确地强制 POSIX)。任何可能会干扰的线索?或者想法如何找出它是什么?

我可以export LC_CTYPE=en_US.UTF-8在我的 .bashrc 中做等,这确实有效。但是,我正在尝试了解这种行为,这与我正在使用的其他 Debian(6 或 7)安装上的行为不同。

编辑:更多细节:

  • 我已经重新启动系统,没有效果;
  • /etc/ssh/sshd_config 有UsePAM yes
  • 我也试过en_US.utf8/etc/default/locale.

小智 0

您应该验证 sshd 配置文件中的 [PermitUserEnvironment] 也设置为 yes。我不知道默认值是什么。