How to constantly change the sudo $ PATH variable (Ubuntu 9.x)

I want to add some directory to $ PATH when running sudo, this is a (semi) permanent requirement, not what needs to be added to the scripts themselves. I noticed that Django managed to do this (my $ PATH when running sudo is "/ usr / local / sbin: / usr / local / bin: / usr / sbin: / usr / bin: / sbin: / bin: / usr / X11R6 / bin: / django / django-trunk / django / bin ") - so how did it work?

+6
path sudo
source share
3 answers

This is the line in the sudoers file that is flushed:

Defaults env_reset

You can get around this by adding PATH to env_keeps or by adding this line:

Defaults env_keep = "PATH"

EDIT: meder, you do not disable env_reset, you just bypass the reset path

Or you can remove the offensive line env_reset .

Even better, you can declare a secure_path that will replace PATH when you run sudo:

Defaults secure_path="/bin:/usr/bin"

This way you can control which specific directories will be included in the path.

+17
source share

I think this should work if you save it in /root/.bashrc:

 export PATH=/www/foo:$PATH 

I forgot that it is PATH or PYTHONPATH, and if that really matters, it is based on my user .bashrc:

 export PYTHONPATH=/www/django:$PYTHONPATH 
+6
source share

You can set the variable in / etc / environment and then use "sudo -i" to run the script (works in ubuntu 10.10).

+3
source share

All Articles