4

for normal user I get :

/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/monty/google_appengine

which is actually the content of /etc/environment

For root I get:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

what's the reason behind this and which file contains this line?

2 Answers2

3

PATH is an environment variable, and therefor it 'defaults' or 'resets' when you change environment. See man sudoers for an explanation:

 env_reset       If set, sudo will reset the environment to only contain
                   the LOGNAME, SHELL, USER, USERNAME and the SUDO_* vari-
                   ables.  Any variables in the caller's environment that
                   match the env_keep and env_check lists are then added.
                   The default contents of the env_keep and env_check
                   lists are displayed when sudo is run by root with the
                   -V option.  If sudo was compiled with the SECURE_PATH
                   option, its value will be used for the PATH environment
                   variable.  This flag is on by default.

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

is the basic path without modifications. Different users will have different directories added to them for several reasons.

And the reasoning should be: root should never ever have more directories in its PATH than needed. Or the other way around: if root needs a file it should be in /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin. You do not play games as root. You do not use a desktop manager as root. A root is for admin tasks.

The wiki has some more information (amongst others which files are used to add to PATH): https://help.ubuntu.com/community/EnvironmentVariables

Rinzwind
  • 309,379
1

In the case of normal user, files such as ~/.profile, ~/.bash_profile, ~/.bashrc might be adding to your default path (which should be the same as the one you listed for root.

You can check any of those files (these are the common ones i know of) for lines such as

export PATH=$PATH:/usr/games:/usr/local/games:/home/monty/google_appengine
or
export PATH=/usr/lib/lightdm/lightdm:$PATH

Edit

.bashrc and .profile seem to have default versions(/etc/profile/ and /etc/bash.basrhc) in /etc/ you can check them for the path for Root.

Additionally, /root/ is the equivalent of /home/<username> for root. I expect that directory has the files ~/.profile, ~/.bash_profile, ~/.bashrc as well, which would also help control the $PATH of root.

Karthik T
  • 2,116