Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Reading the man pages I expected sudo -E to pass all environment variables to the subshell, but I am not getting the expected results.

As expected, awesome:

$ export LD_LIBRARY_PATH=/home/mmendez/toolchains/x86-destdir/usr/lib/
$ env | grep LD
LD_LIBRARY_PATH=/home/mmendez/toolchains/x86-destdir/usr/lib/

More awesomeness:

$ env -i LD_LIBRARY_PATH=/tmp/no/where env | grep LD
LD_LIBRARY_PATH=/tmp/no/where

Not what was expected:

$ env -i LD_LIBRARY_PATH=$LD_LIBRARY_PATH sudo -E /usr/bin/env | grep LD
$
$ env -i LD_LIBRARY_PATH=/tmp/no/where sudo -E /usr/bin/env | grep LD
$

So, how can I get sudo -E to pass LD_LIBRARY_PATH, without editing /etc/sudoers?

Edit:

According to How do I make sudo preserve my environment variables? the OP indicates that the shell may play a role in conjunction with !env_reset. I am running Arch Linux and the default shell is BASH. Once again, I do not want to edit /etc/sudoers, is it possible?

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

Certain environment variables, including LD_LIBRARY_PATH or HOSTALIASES (full list is in sysdeps/generic/unsecvars.h), are automatically unset by glibc when executing a privileged program (i.e. with the setuid bit or with filesystem capabilities). This is a security feature, since otherwise users could load their own libraries into su or sudo and trick them into accepting any password.

You will need to use sudo env LD_LIBRARY_PATH=$LD_LIBRARY_PATH yourcommand in order to pass the variable to commands run via sudo.

share|improve this answer
    
Ahh, ok thanks. –  mmlb Jan 31 '13 at 17:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.