I've just spun up a brand new CentOS 7 VM (bash version 4.2.46) with Vagrant using the centos/7 box, and when I'm logged in as the vagrant user, this is my PATH:
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/vagrant/.local/bin:/home/vagrant/bin
When logged in as root, here's the PATH:
/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
I know that /etc/profile
is adding /usr/local/sbin:/usr/sbin
(at the end for most users, at the start for root), and the /etc/skel/.bash_profile
that ends up in the vagrant home directory is adding /home/vagrant/.local/bin:/home/vagrant/bin
, but where is the initial setting coming from?
At present I have no explanation of why users end up with /usr/local/bin:/usr/bin
in their PATH, and root gets the others.
(Frankly, the ordering of the root PATH seems very odd, given that /usr/local/sbin
and /usr/sbin
should be at the end, according to /etc/profile
.)
Other people have asked the same thing on the CentOS bug tracker. The earliest post I found was this one.
/usr/local/bin is hardcoded in /bin/bash.
As you will see this problem was first reported in May 2012, and has existed in CentOS 6 and CentOS 7.
So as confusing as it may be, it looks like your analysis the paths are not coming from /etc/profile is correct. The paths are coming from /bin/bash.
In the bash source "config-top.h" has this:
It definitely looks hard coded into
/bin/bash
which seems to be the default PATH.
In addition to previous answers; If you are reaching you VM by ssh this could has sense.
In
/etc/ssh/sshd_config
:I came across this today (in my case it wasn't present in the PATH) and I realized this only happens in login shells. If you run a shell as another user
/usr/local/bin
won't get added to the path (For examplesu <username>
). Maybe that's what happens with vagrant