Ubuntu – The value of $PATH is different for root and normal user

12.10environment-variablesroot

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?

Best Answer

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