1

Platform: Ubuntu 10.04 VM running out of VirtualBox

File details:

-rwxr-x---  1 myuser myuser  123 2013-10-31 16:10 myscript.sh

The executable is visible in the directory:

>type myscript.sh
myscript.sh is ./myscript.sh

I do have . in the path:

>echo $PATH
.:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Running it without sudo works fine:

>myscript.sh

but not with sudo:

>sudo myscript.sh
sudo: myscript.sh: command not found

Why?

1
  • 1
    PATH is not inherited in sudo. Doing so would be a security flaw since someone might stick something unsafe in PATH such as ..
    – jordanm
    Oct 31, 2013 at 20:32

1 Answer 1

4

Sudo resets PATH, along with many other environment variables, for security reasons. It doesn't matter what is set in /etc/profile, unless you run sudo -i.

The sudo manual page, under SECURITY NOTES, gives an insight about the security implications, along with the options you have to fiddle in your /etc/sudoers file to modify these restrictions, after you understand the implications of doing so."

Source: https://serverfault.com/questions/11899/how-to-override-a-path-environment-variable-in-sudo

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