How do I make sudo preserve my environment variables?
Problem
Using sudo 1.7.4p4 on Solaris 5.10 and sudo 1.6.7p5 on RHEL4 u6 I can't see how to preserve my environment variables, for instance $PYTHONPATH. I've added this line to sudoers, but it doesn't make any difference: Am I doing something wrong, or is the sudo installation simply not respecting the env_reset flag? Edit: At least on Solaris, we've found that this issue depends on the shell! The standard root shell is Bourne, if we run bash under sudo ( ) on the other hand, !env_preset will preserve the environment (including PATH and LD_LIBRARY_PATH). This is rather confusing behaviour I have to say.
Error Output
Defaults !env_reset
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix for: How do I make sudo preserve my environment variables?
Use carefully, there are security issues with sudo and variables. From I found that you should use In Ubuntu, does preserves some variables. is more like logging in as root and then running the command. Both may be inconvenient, the former for leaves root-owned files inside your home and the latter for will try to open /root/myfile. Run and see what it gives. Here it gives for example. Now run and add the line replacing by what you found just before. Append a new path to it if you need. About l…
Awaiting Verification
Be the first to verify this fix
Sign in to verify this fix