Proxy does not work using sudo
Solution 1
In case anybody wonders:
The issue here, is that when sudoing, a newenvironment is loaded, meaning that http_proxy is no longer set.
To resolve this issue you can add Defaults env_keep += "http_proxy https_proxy"
to your /etc/sudoers file in order to keep those variables when switching to the secure path.
Reference: https://help.ubuntu.com/community/EnvironmentVariables
Solution 2
Open /etc/apt/apt.conf
file in Terminal and set your proxy setting as following:
Acquire::http::proxy "http://user:pass@host:port/";
Acquire::https::proxy "https://user:pass@host:port/";
Acquire::ftp::proxy "ftp://user:pass@host:port/";
Acquire::socks::proxy "socks://user:pass@host:port/";
Replace user
with your username, pass
with your password, host
with proxy-webaddress and port
with a portnumber.
Related videos on Youtube
Michele
Recently moved to an IT consultancy position after having spent 6 years studying condensed matter physics.
Updated on September 18, 2022Comments
-
Michele over 1 year
I set the proxy using system setting -> Network -> Network Proxy. I then clicked on "Apply system wide", put my password, and nothing else.
michele@rserver-VirtualBox:~$ wget http://bbc.co.uk --2014-09-30 13:02:20-- http://bbc.co.uk/ Resolving datapx01-wcg (datapx01-wcg)... 10.123.7.31 Connecting to datapx01-wcg (datapx01-wcg)|10.123.7.31|:8080... connected. Proxy request sent, awaiting response... 301 Moved Permanently Location: http://www.bbc.co.uk/ [following] --2014-09-30 13:02:21-- http://www.bbc.co.uk/ Reusing existing connection to datapx01-wcg:8080. Proxy request sent, awaiting response... 200 OK Length: 103020 (101K) [text/html] Saving to: ‘index.html’ 100%[======================================>] 103,020 190KB/s in 0.5s 2014-09-30 13:02:21 (190 KB/s) - ‘index.html’ saved [103020/103020]
Instead using sudo:
michele@rserver-VirtualBox:~$ sudo wget http://bbc.co.uk [sudo] password for michele: --2014-09-30 13:02:30-- http://bbc.co.uk/ Resolving bbc.co.uk (bbc.co.uk)... 212.58.246.104, 212.58.244.20, 212.58.246.103, ... Connecting to bbc.co.uk (bbc.co.uk)|212.58.246.104|:80... failed: Connection timed out.
I am on 14.04 and I didn't have this issue before upgrading from 12.04 yesterday. Please tell me what other info you need.
-
αғsнιη over 9 yearsWhy do you want to use
sudo
here while it works well without that? -
αғsнιη over 9 yearsCheck your
/etc/apt/apt.conf
file and see if your proxy setting is also appear there. -
Michele over 9 yearsthat is simply a reproducible example... my server runs application on behalf of different users, so I need the proxy to work for all users.
-
s3lph over 9 yearsTo workaround, use it like this:
sudo env HTTP_PROXY=http://proxy.example.com:port wget http://bbc.co.uk
. -
Lety over 9 yearsDid you try @the_Seppi's suggestion? When you run sudo, environment is restricted.
-
Michele over 9 years@Letizia yes, it did not work
-
Lety over 9 yearsDid you try to configure and uncomment http_proxy in
/etc/wgetrc
file? -
Jones03 about 8 yearsYou need to make some changes in your /etc/sudoers file. Take a look at this: ubuntuforums.org/showthread.php?t=2199416.
-
-
Michele over 9 yearsThose 4 lines are already there. But without the username and password. I ll try adding them
-
Michele over 9 yearsJust did, still the same
-
αғsнιη over 9 years@Michele run
echo $http_proxy
in terminal did you see the your user and pass and other configure? -
Michele over 9 yearsI just get the
http://proxy:port/
-
αғsнιη over 9 years@Michele then your user and pass not set correctly!!
-
Michele over 9 yearstriple checked they are fine
-
αғsнιη over 9 yearsdid you restart the system
-
Michele over 9 yearsNo, I thought it was a Windows thing... :-) I'll try now
-
Michele over 9 yearsNada... still the same. I just read that sudo does a reset of the environment variables and things like http_proxy don't get used
-
αғsнιη over 9 years@Michele Sorry but I don't have any idea check here askubuntu.com/questions/175172/… and here askubuntu.com/questions/15719/… and also here askubuntu.com/questions/82880/…
-
Ubuntuser about 6 yearssuper answer!! worked in CentOS 7 as well.
-
rbaleksandar about 2 yearsJust a note: this would still requires the respective environment variables to be set inside the profile of the user, who belongs to the sudoers. Add
export http_proxy=...
andexport https_proxy=...
to.bashrc
or whatever your user's profile file is called. Also I recommend puttingno_proxy
, which is quite common for company networks, where internal network locations (e.g. intranet web portal) often not only do not require but will not work if going through proxy.