为什么通过 ssh 登录时没有获取 /etc/default/locale?

为什么通过 ssh 登录时没有获取 /etc/default/locale?

我不是新手,但我已经与这个看似简单的问题斗争了一段时间。我知道如何用/etc/environment或其他技巧来解决这个问题,但我希望变量能/etc/default/locale起作用……它们根本没有来源

使用 Ubuntu 14.04.4。当前内容为/etc/default/locale

LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_ALL=en_US.UTF-8

我知道我可以把它们放进去/etc/environment/etc/profile等等。触发dpkg-reconfigure locales,,locale-gen没有locale-update任何效果。我知道所有这些。

应该提供来源的东西/etc/default/locale没有提供来源。我不知道是什么。我也重启了。

这是我通过 ssh 进入机器的时候。

答案1

...几分钟后我就明白了...该死的 PAM!

通过查看所有 /etc 文件(来源为 /etc/default/locale)来追踪它,结果发现了 PAM。它将其来源设为/etc/pam.d/sshd

然后我记得我最近才在想通过 chroot 监禁 sftp 用户时/etc/ssh/sshd_config通过注释该行禁用了 PAM。#UsePAM yes

解决方案:在 sshd_config 中重新启用 PAM,或者在 /etc/environment、/etc/profile 或 ~/.profile 中源 /etc/default/locale

如果愿意,版主可以删除这个问题和这个答案。我会保留它们,以防其他人也遇到同样的问题。

然而!

这难道不应该是一个值得向 Ubuntu 开发人员报告的错误吗?无论是否使用 PAM,是否都应该在所有登录上配置区域设置?

答案2

阅读man ssh,其中部分内容如下ENVIRONMENT

 Additionally, ssh reads ~/.ssh/environment, and adds lines of the format
 “VARNAME=value” to the environment if the file exists and users are
 allowed to change their environment.  For more information, see the
 PermitUserEnvironment option in sshd_config(5).  

并且,在本FILES节中参见:

 ~/.ssh/environment
         Contains additional definitions for environment variables; see
         ENVIRONMENT, above.

 ~/.ssh/rc
         Commands in this file are executed by ssh when the user logs in,
         just before the user's shell (or command) is started.  See the
         sshd(8) manual page for more information.

 /etc/ssh/sshrc
         Commands in this file are executed by ssh when the user logs in,
         just before the user's shell (or command) is started.  See the
         sshd(8) manual page for more information.

相关内容