0

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

  • How do you log in as root? – Kusalananda Aug 24 '18 at 12:24
  • Did a sudo -i – pkaramol Aug 24 '18 at 12:26
  • sudo may well set the PATH for root to some predetermined value or there may be some other security policy in place that changes the PATH from what's in /etc/environment. – Kusalananda Aug 24 '18 at 12:28
  • This may be closely related: unix.stackexchange.com/questions/8646/… – Kusalananda Aug 24 '18 at 12:32
  • @Kusalananda pls check my update on the topic – pkaramol Aug 24 '18 at 12:42
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.