4

I am having trouble getting pip to work behind a corporate firewall. I added the http and https proxies to my /etc/environment file, and if I execute echo "$HTTP_PROXY" it prints the right thing. However, if I execute env or printenv none of the proxy variables show up. I think this is why pip is failing too. Any insight would be appreciated. My /etc/environment file looks like

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
http_proxy="http://<stuff>.<stuff>.org:80"
HTTP_PROXY="http://<stuff>.<stuff>.org:80"
https_proxy="https://<stuff>.<stuff>.org:443"
HTTPS_PROXY="https://<stuff>.<stuff>.org:443"

And I added the same lines to my ~/.bashrc file as well.

Zanna
  • 72,471
irh
  • 227
  • Did you login again after adding to /etc/environment? Did you use export when adding to ~/.bashrc? – muru Jun 13 '18 at 14:25
  • I didn't use export in the .bashrc file. Thanks for pointing that out. Also, I'm not sure I have logged in again either. I restarted my whole computer, but I am running windows subsystem for Linux (sadface) and it doesn't ask for my credentials on start up, so maybe something funny is going on there. – irh Jun 13 '18 at 14:29
  • adding the "export" did the trick! Thank you! – irh Jun 13 '18 at 14:35
  • I don't know if WSL uses the usual login mechanisms, it probably doesn't. – muru Jun 13 '18 at 14:35

2 Answers2

7

WSL doesn't use the PAM stack when starting a shell (login or not), so PAM-based things fail:

  • /etc/environment and ~/.pam_environment, read by pam_env, don't apply (WSL #1405)
  • default umask from pam_umask isn't set (WSL #352)
  • limits from pam_limits (WSL #1576)

Specifically for environment settings, it might be simplest to just add those to .profile (if running login shells) or .bashrc, with export.


Generally, there doesn't seem to be a simple solution.

You could log in again as your user:

sudo -iu "$USER"
su - "$USER"

These should load the PAM configuration in /etc/pam.d/sudo or /etc/pam.d/su respectively. But these are slightly different from each other, and also different from /etc/pam.d/sshd or /etc/pam.d/lightdm, so not everything would be the same as if you logged into an actual Ubuntu system via the GUI or SSH.

(Both sudo and su would ask for passwords, but both can be configured to not ask for passwords.)

Zanna
  • 72,471
muru
  • 207,970
-1

The issue you're having as due to "bash not picking up /etc/environment" in WSL. I stumbled upon it and it's nasty. What's more nasty is that it's a 7 years old issue, as of writing, still not solved. I'm copying my workaround from the issue, for whoever is landing here:


To celebrate the 7 years anniversary of this issue in 10 days, I present you my workaround, based on @smaktacular 's one, that combines /etc/environment & your current $PATH set elsewhere (eg Windows Paths set by WSL, other export PATH= in .bashrc/.zshrc etc):

At the end of your .bashrc or .zshrc add the following:

export PATH_TEMP=$PATH
while read line; do export $line; done < /etc/environment
# $PATH now is "/some/paths:/..." but we need to omit first & last chars (the quotes)
export PATH=$PATH_TEMP:${PATH:1:${#PATH}-2}
unset PATH_TEMP

Done - It took me a bit more than 7 minutes, it will take you a bit more than 7 seconds.

Happy 7 years anniversary!

PS:> Make sure you have a newline at the end of /etc/environment otherwise read line breaks ;-)