Working on Ubuntu 16.04.05
.
According to the official debian and ubuntu documentations, variables declared therein should be inherited by all users;
Then how is the following explained:
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
(i.e. paths in /etc/environment
not ending up in root
PATH
) given that no explicit PATH
override seems to take place in:
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) in /etc/profile.d/
there is only a PATH
expansion to account for /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
Update:
Regarding relation to this issue as pointed out by @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:~#
However:
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"
So it seems the secure_path
is applied in both su
and sudo
cases? (which is not what the related issue states).
sudo -i
– pkaramol Aug 24 '18 at 12:26sudo
may well set thePATH
for root to some predetermined value or there may be some other security policy in place that changes thePATH
from what's in/etc/environment
. – Kusalananda Aug 24 '18 at 12:28