1

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).

pkaramol
  • 2,799
  • 6
  • 47
  • 79

1 Answers1

4

The default paths come from /etc/login.defs, which contains (in Debian at least, I suspect it’s the same in 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

This is mentioned at the bottom of the Debian wiki page you linked to, in the context of su.

Stephen Kitt
  • 434,908