sudo usa um mínimo PATH , para torná-lo seguro para o usuário root . Isso não é necessariamente o mesmo que o PATH que você obteria fazendo login como o usuário root , ou fazendo
sudo su -
Por exemplo, em versões mais recentes da Red Hat, notei que o caminho omite /usr/local/bin .
A página de manual resume isso em uma seção intitulada Notas de segurança :
sudo tries to be safe when executing external commands.
There are two distinct ways to deal with environment variables. By default, the
env_resetsudoers option is enabled. This causes commands to be executed with a minimal environment containingTERM,PATH,HOME,SHELL,LOGNAME,USERandUSERNAMEin addition to variables from the invoking process permitted by theenv_checkandenv_keepsudoers options. There is effectively a whitelist for environment variables.
Leitura adicional:
-
sudoers - lista de quais usuários podem executar o que
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 theexempt_groupoption are not affected bysecure_path. This option is not set by default.