I set PATH in /etc/profile
. I do not have any problems in the case of the general user, but PATH does not go when I become the root authority in sudo
.
What would you do to override the PATH
which is set by /etc/profile
even if I become the root authority in sudo
?
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.
root's path is not changed by /etc/profile (security ...)
you have to set it up separately, (e.g. in root's ~/.bash_profile)
update:
If you want to add a specific PATH to the default PATH of your "root" account when using sudo, or sudo -i:
With Ubuntu 10.04.x LTS:
Modify accordingly both the /etc/environment and the etc/login.defs files.
With Ubuntu 12.04.x LTS:
Modify accordingly both the /etc/environment and the /etc/login.defs files as well as the line Defaults secure_path of the /etc/sudoers file (using visudo).
If you're using a GUI and aren't comfortable with the nano editor in text mode, use the following command to edit the /etc/sudoers file with gedit:
sudo EDITOR=gedit visudo
When you'll save the /etc/sudoers file, visudo will check the syntax of your modifications.
If all is OK, you'll go back to the terminal session.
If there is an error, press the letter "e" to edit the /etc/sudoers file again and correct your modification.
I didn't try with Ubuntu 12.10 yet but I guess (and hope) it's the same thing than for Ubuntu 12.04.x!
Cheers.
In case if your Linux distributions has security policy plugin enabled, the
PATH
can be overridden bysecure_path
in yoursudoers
file, so you need to edit it bysudo visudo
and add it to the list.You can check that if that's the case by:
Alternatively for one-time use, try:
See: Why are PATH variables different when running via sudo and su? at Unix SE