/etc/environment 中声明的 PATH env var 不继承?

/etc/environment 中声明的 PATH env var 不继承?

致力于Ubuntu 16.04.05.

据官方称德比安乌班图文档,其中声明的变量应由所有用户继承;

那么下面的内容是如何解释的:

root@pkara-pc01:~# cat /etc/environment 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
root@pkara-pc01:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin

(即路径/etc/environment未结束于root PATH)鉴于PATH似乎没有显式覆盖发生在:

A)/root/.profile

root@pkara-pc01:~# grep -i path /root/.profile
root@pkara-pc01:~# 

b)/root/.bashrc

root@pkara-pc01:~# grep -i path /root/.bashrc
root@pkara-pc01:~# 

C)/etc/profile

root@pkara-pc01:~# grep -i path /etc/profile
root@pkara-pc01:~# 

d)/etc/profile.d/只需要PATH进行扩展即可/snap/bin

root@pkara-pc01:~# grep -rniI -A 1 path /etc/profile.d/
/etc/profile.d/apps-bin-path.sh:3:# Expand $PATH to include the directory where snappy applications go.
/etc/profile.d/apps-bin-path.sh:4:if [ "${PATH#*/snap/bin}" = "${PATH}" ]; then
/etc/profile.d/apps-bin-path.sh:5:    export PATH=$PATH:/snap/bin
/etc/profile.d/apps-bin-path.sh-6-fi

更新:

关于与这个问题正如@Kusalandra 所指出的,

$ su -
Password: 
root@pkara-pc01:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
root@pkara-pc01:~# exit
logout
/home/pkara/Workspace/gitlab/sonar-scanner
$ sudo -i
root@pkara-pc01:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
root@pkara-pc01:~# 

然而:

root@pkara-pc01:~# grep -i secure_path /etc/sudoers
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

所以看来secure_path应用在两个都 susudo案例? (这是不是相关问题的说明)。

答案1

默认路径来自/etc/login.defs,其中包含(至少在 Debian 中,我怀疑它在 Ubuntu 中是相同的):

#
# *REQUIRED*  The default PATH settings, for superuser and normal users.
#
# (they are minimal, add the rest in the shell startup files)
ENV_SUPATH      PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV_PATH        PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

这在底部提到Debian 维基页面您在 的上下文中链接到su

相关内容