我刚刚使用centos / 7盒子创build了一个全新的CentOS 7虚拟机(bash版本4.2.46),当我以stream浪用户的身份login时,这是我的path:
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/vagrant/.local/bin:/home/vagrant/bin
以root身份login时,这是PATH:
/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
我知道/etc/profile正在添加/usr/local/sbin:/usr/sbin (大多数用户的末尾,root的开始处)以及/etc/skel/.bash_profile结尾在stream浪汉主目录join/home/vagrant/.local/bin:/home/vagrant/bin ,但是初始设置来自哪里?
目前我没有解释为什么用户在他们的PATH中使用/usr/local/bin:/usr/bin ,而root使用其他的。
(坦率地说,根path/etc/profile ,根path的sorting看起来很奇怪,因为/usr/local/sbin和/usr/sbin应该在最后。
在bash源文件“config-top.h”中有这个:
/* The default value of the PATH variable. */ #ifndef DEFAULT_PATH_VALUE #define DEFAULT_PATH_VALUE \ "/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:." #endif /* The value for PATH when invoking `command -p'. This is only used when the Posix.2 confstr () function, or CS_PATH define are not present. */ #ifndef STANDARD_UTILS_PATH #define STANDARD_UTILS_PATH \ "/bin:/usr/bin:/sbin:/usr/sbin:/etc:/usr/etc" #endif
其他人在CentOS bug追踪器上也有同样的要求。 我发现的最早的post就是这个 。
/ usr / local / bin在/ bin / bash中硬编码。
你将会看到这个问题在2012年5月首次被报道,并且已经存在于CentOS 6和CentOS 7中。
因此,尽可能混淆,看起来像你的分析path不是来自/ etc / profile是正确的。 path来自/ bin / bash。
它绝对看起来硬编码到/bin/bash
strings /bin/bash | grep "\/usr\/local\/bin" /usr/local/bin:/bin:/usr/bin
这似乎是默认的PATH。
除了以前的答案, 如果你通过ssh到达你的VM,这可能是有道理的。
在/etc/ssh/sshd_config :
# This sshd was compiled with PATH=/usr/local/bin:/usr/bin