# questions about "sudo -E "



## fwin (Aug 28, 2012)

Hi everyone,

I was trying to install a package using *sudo pkg_add -r <pkgname>* and I noticed that pkg_add(1) was not using the PACKAGESITE variable that I had set in my .cshrc file. In order to make this work I had to set PACKAGESITE in /root/.cshrc and then login as root (or use su(1)) to be able to install the packgae from the appropriate site. 

After I set PACKAGESITE in /root/.cshrc, I also tried to install another package using *sudo pkg_add -r <pkgname>* but it did not work. At this point, I started googling, reading man pages, etc. and I found out that sudo(8) was the problem, for some reason it was not using my environment variables, and in order to make it use them I had to do *sudo -E*. 

Okay so here are my questions:

1. Is it okay if I do an alias in my .cshrc file (i.e. *alias sudo   sudo -E*) so that I don't have to use *sudo -E* all the time?

2. Will forcing sudo(8) to use my environment variables create problems if I use it for anything else besides pkg_add(1)?

3. Is there a reason why sudo(8) is set by default to ignore the environment variables?

Thanks in advance!!


----------



## Beeblebrox (Aug 28, 2012)

What you want to do will work, but it's not the proper way. You should place whatever you want after below code in the sudoers file.

```
Defaults env_keep +="  "
```
Read /usr/local/etc/sudoers.sample to understand the "proper way" and the reason that what you want to do may be inappropriate. For single-user PC's the warnings mentioned in the file are probably not that important and those warnings pertain more to server systems. Your call.


----------



## fwin (Aug 29, 2012)

Thank you very much Beeblebrox, I just tried that and it worked. 
I had read /usr/local/etc/sudoers.sample[.file] but I guess I did not pay attention to that part.

Thanks Again!!


----------

