关于locale.conf 加载的问题分析
关于 /etc/locale.conf 加载的问题分析
实例分析(这里以centos 7 为例)
[root@ds147000 ~]# cat /etc/locale.conf
LANG="en_US.UTF-8"
从 DS046010 ssh ds147000, LANG 继承了原来的设置
[chkusr@DS046010 ~]$ LANG=en_US
[chkusr@DS046010 ~]$ locale
LANG=en_US
LC_CTYPE="en_US"
LC_NUMERIC="en_US"
LC_TIME="en_US"
LC_COLLATE="en_US"
LC_MONETARY="en_US"
LC_MESSAGES="en_US"
LC_PAPER="en_US"
LC_NAME="en_US"
LC_ADDRESS="en_US"
LC_TELEPHONE="en_US"
LC_MEASUREMENT="en_US"
LC_IDENTIFICATION="en_US"
[chkusr@DS046010 ~]$ ssh 10.1.105.98
WARNING: If you are not authorized to access this private computer system, disconnect now. All activities on this system will be monitored and recorded without prior notification or permission!
[chkusr@ds147000 ~]$ locale
LANG=en_US
LC_CTYPE="en_US"
LC_NUMERIC="en_US"
LC_TIME="en_US"
LC_COLLATE="en_US"
LC_MONETARY="en_US"
LC_MESSAGES="en_US"
LC_PAPER="en_US"
LC_NAME="en_US"
LC_ADDRESS="en_US"
LC_TELEPHONE="en_US"
LC_MEASUREMENT="en_US"
LC_IDENTIFICATION="en_US"
修改语言为 en_US.UTF-8, 再次登录验证。
[chkusr@DS046010 ~]$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
[chkusr@DS046010 ~]$ ssh 10.1.105.98
Last login: Tue Jun 26 15:11:41 2018
WARNING: If you are not authorized to access this private computer system, disconnect now. All activities on this system will be monitored and recorded without prior notification or permission!
[chkusr@ds147000 ~]$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
从办公电脑直接 ssh ds147000 , 因 LANG 等为空,所以读取 /etc/locale.conf 设置语言。
[Rocky.DS-TS-0161] ➤ ssh 10.1.105.98 -l chkusr
Warning: Permanently added '10.1.105.98' (RSA) to the list of known hosts.
chkusr@10.1.105.98\'s password:
WARNING: If you are not authorized to access this private computer system, disconnect now. All activities on this system will be monitored and recorded without prior notification or permission!
[chkusr@ds147000 ~]$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
我们从审计中可以看到从 客户端 ssh ds147000, 文件读取过程。
time->Tue Jun 26 15:32:07 2018
type=PATH msg=audit(1529998327.385:393119): item=0 name="/etc/locale.conf" inode=35413544 dev=fd:00 mode=0100644 ouid=0 ogid=0 rdev=00:00 objtype=NORMAL
type=CWD msg=audit(1529998327.385:393119): cwd="/home/chkusr"
type=SYSCALL msg=audit(1529998327.385:393119): arch=c000003e syscall=2 success=yes exit=3 a0=227cb20 a1=0 a2=4355b0 a3=fffffffffffff247 items=1 ppid=11944 pid=11949 auid=698 uid=698 gid=801 euid=698 suid=698 fsuid=698 egid=801 sgid=801 fsgid=801 tty=(none) ses=55758 comm="bash" exe="/usr/bin/bash" key="locale.conf"
----
time->Tue Jun 26 15:32:07 2018
type=PATH msg=audit(1529998327.388:393120): item=0 name="/etc/locale.conf" inode=35413544 dev=fd:00 mode=0100644 ouid=0 ogid=0 rdev=00:00 objtype=NORMAL
type=CWD msg=audit(1529998327.388:393120): cwd="/home/chkusr"
type=SYSCALL msg=audit(1529998327.388:393120): arch=c000003e syscall=2 success=yes exit=3 a0=14921b0 a1=0 a2=4355b0 a3=fffffffffffffa27 items=1 ppid=11936 pid=11939 auid=698 uid=698 gid=801 euid=698 suid=698 fsuid=698 egid=801 sgid=801 fsgid=801 tty=pts4 ses=55757 comm="bash" exe="/usr/bin/bash" key="locale.conf"
----
summary
用户ssh登录系统,如果有 LANG 等变量,会自动继承过去,如果没有则读取 /etc/locale.conf (CentOS 5/6:/etc/sysconfig/i18n) 来设置语言。
登录系统后,su – 切换其它用户会读取 /etc/locale.conf or /etc/sysconfig/i18n 来设置语言。