6

I installed eclipse in my home directory, and put its path in PATH in ~/.profile.

So it works by

$ eclipse 

But when call it with sudo, eclipse isn't found:

$ sudo eclipse 
sudo: eclipse: command not found

Which PATH does sudo eclipse use to search for eclipse? Is it the user root's PATH?

Thanks.

Tim
  • 101,790

1 Answers1

7

sudo by default uses a minimal PATH, to make it safe for use by the root user. That is not necessarily the same as the PATH you would get by logging in as the root user, or by doing

sudo su -

For instance, in newer Red Hat releases, I've noticed that the path omits /usr/local/bin.

The manual page summarizes this in a section entitled Security Notes:

sudo tries to be safe when executing external commands.

There are two distinct ways to deal with environment variables. By default, the env_reset sudoers option is enabled. This causes commands to be executed with a minimal environment containing TERM, PATH, HOME, SHELL, LOGNAME, USER and USERNAME in addition to variables from the invoking process permitted by the env_check and env_keep sudoers options. There is effectively a whitelist for environment variables.

Further reading:

  • sudoers - list of which users may execute what

    secure_path
    Path used for every command run from sudo. If you don't trust the people running sudo to have a sane PATH environment variable you may want to use this. Another use is if you want to have the "root path" be separate from the "user path." Users in the group specified by the exempt_group option are not affected by secure_path. This option is not set by default.

  • sudo - execute a command as another user

Thomas Dickey
  • 76,765
  • Thanks. Wonder why linux doesn't have a manpage for sudo. see http://man7.org/linux/man-pages/dir_section_1.html and http://man7.org/linux/man-pages/dir_section_8.html – Tim Jul 06 '16 at 12:05
  • How can I get and set the values of the PATH used by sudo? 2. Is it correct that its PATH is not used by any other user including root?
  • – Tim Jul 06 '16 at 12:42