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 Answers 2

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

3
  • But when we change the environment file, I think the changes are seen by all users except root, isn't it? So how can I change the path for root then? Nov 20, 2012 at 9:51
  • Yes, ofcourse. Users logging into a DM are the same (the all use /etc/environment). Oh and sudo -i makes it use /etc/environment' too ;) And the last question: check man sudoers`. There are several options there. But why would you need to change root? There should be no reason for it.
    – Rinzwind
    Nov 20, 2012 at 10:01
  • In fact the result I posted for root came from sudo -i command, and after doing su root the value of $PATH returned was same as it was for a normal user,any ideas on that? There should be no reason for it? yes, I want to change it only for learning purpose. Nov 20, 2012 at 10:25
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.

2
  • I can't seem to find .profile and .bashrc in /etc. Nov 20, 2012 at 9:51
  • in /etc/ it is just /etc/profile/ and /etc/bash.bashrc according to Ubuntu Documentation, Sorry for not being clear
    – Karthik T
    Nov 20, 2012 at 9:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .