Sudo – What Environment is Provided with Sudo?

environment-variablessudo

When I run sudo, what exactly happens to my environment?

When I run sudo command, it doesn't seem to see my or root's environment. For example, my path for both includes /usr/local/bin, but if I try to run one of the program's without the full path, it fails.

I thought sudo ran as root, and hence got root`s environment. Is there a different way that bash executes under sudo than under root or my normal user?

EDIT:

I have been using sudo -i lately, but recently it has been causing problems because my current working directory gets set to /root. This is as expected (sorta), but I still don't understand why sudo isn't recognizing my executables in /usr/local/bin.

EDIT:

I am running Fedora 15.

Best Answer

I don't know about the defaults on Fedora, but on Debian sudo defaults to using the secure_path option with a default value of /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin.

This means the path is changed to that value every time you use sudo; but when you use sudo -i, the path is changed after that by the root user's RC files.

Related Question