Setting Up wget Behind a Proxy That Needs a Login
By the ProxyV4 Engineering Team · Updated:
To give wget a proxy username and password, pass --proxy-user=USER --proxy-password=PASS alongside the proxy address, or embed them in the proxy URL as http://USER:PASS@IP:PORT. You can set the address through command-line -e options, the lowercase http_proxy and https_proxy variables, or a wgetrc file. One limit up front: GNU wget only talks to HTTP proxies, so SOCKS5 needs a different tool.
A one-off wget download through a proxy
When you need the proxy for a single command and nothing else, put everything on the command line. -e runs a wgetrc command, so the proxy settings exist only for this run:
wget -e use_proxy=on \
-e http_proxy=http://203.0.113.10:PORT \
-e https_proxy=http://203.0.113.10:PORT \
--proxy-user=USER --proxy-password=PASS \
-qO- https://proxyv4.com/api/my-ipThe output is the JSON from an IP echo service; the ip field should be the proxy's address. Note that https_proxy points at an http:// URL. That is correct: wget talks plain HTTP to the proxy and sends a CONNECT request to open a tunnel for the HTTPS site.
Command-line passwords end up in shell history and are briefly visible to other users in the process list. That is fine for a quick test on your own machine. On shared servers, use a wgetrc file with tight permissions instead.
wget https_proxy and other environment variables
Exporting the variables makes every later wget in that shell use the proxy, along with curl, apt and many other tools that read the same names:
export http_proxy="http://USER:[email protected]:PORT"
export https_proxy="http://USER:[email protected]:PORT"
export no_proxy="localhost,127.0.0.1,.internal.example"
wget -qO- https://proxyv4.com/api/my-ipStick to lowercase names
The wget manual documents http_proxy, https_proxy, ftp_proxy and no_proxy in lowercase. Some builds also read uppercase variants and others do not, so use the lowercase spelling and you will not have to find out which build you have. If a tool you also rely on wants HTTPS_PROXY, export both.
Encoding the password in a URL
Inside a URL, @, :, / and # in the password break parsing; wget may report Bad port number or connect to the wrong host. Percent-encode the password once and paste the result into the variable:
python3 -c 'import urllib.parse,sys; print(urllib.parse.quote(sys.argv[1], safe=""))' 'p@ss:w/rd'
# p%40ss%3Aw%2FrdAlternatively keep the variable free of credentials and supply --proxy-user and --proxy-password, which take the raw values.
How no_proxy matches
no_proxy is a comma-separated list of domain suffixes. .internal.example covers every host under that domain. Keep internal mirrors and metadata endpoints in it so they do not detour through an external IP.
Making it permanent with wgetrc proxy settings
For servers and service accounts, a wgetrc file keeps the proxy and its login out of scripts and out of ps. The user file is ~/.wgetrc; the system-wide file is usually /etc/wgetrc on Debian and Ubuntu, though the path depends on how wget was built. Commands in a user file override the system file.
# ~/.wgetrc (chmod 600 ~/.wgetrc)
use_proxy = on
http_proxy = http://203.0.113.10:PORT/
https_proxy = http://203.0.113.10:PORT/
proxy_user = USER
proxy_password = PASS
no_proxy = localhost,127.0.0.1,.internal.exampleThe use_proxy setting is the master switch. When it is off, wget connects directly even if proxy variables are set. Settings from wgetrc and the command line take priority over the environment, and -e on the command line beats both files, which gives you a clean override path for testing.
Bypassing the proxy for one download
Two equivalent ways to skip the configured proxy without editing anything:
wget --no-proxy https://repo.internal.example/file.tar.gz # skip the proxy once
wget -e use_proxy=off https://example.com/ # same effect via a commandUsing SOCKS5 when wget cannot
GNU wget has no SOCKS client, so pointing https_proxy at a socks5:// URL does not work. You have three practical routes, in order of simplicity.
Switch the proxy to HTTP mode
Many providers let one proxy speak both protocols. If yours does, use the HTTP side for wget and keep SOCKS5 for the tools that need it. Nothing else in this article changes.
Use curl for that download
curl supports SOCKS5 with a login, and socks5h makes the proxy resolve the hostname. -fLO makes it fail on HTTP errors, follow redirects and save with the remote filename, which covers most wget use:
curl -x socks5h://USER:[email protected]:PORT -fLO https://example.com/file.tar.gz
# Equivalent long form
curl --socks5-hostname 203.0.113.10:PORT --proxy-user USER:PASS \
-fLO https://example.com/file.tar.gzThe curl proxy guide covers its other options.
Wrap wget with proxychains-ng
proxychains-ng intercepts a program's network calls and sends them through a SOCKS or HTTP proxy, so wget itself stays unchanged. Configure the proxy once:
# /etc/proxychains4.conf (or ~/.proxychains/proxychains.conf)
strict_chain
proxy_dns
[ProxyList]
socks5 203.0.113.10 PORT USER PASSsudo apt install proxychains4 # Debian/Ubuntu package name
proxychains4 -q wget https://example.com/file.tar.gzproxy_dns sends hostname lookups through the proxy. proxychains works through LD_PRELOAD, so it cannot wrap statically linked binaries, and it is a poor fit for long-running services.
Scripts, cron, sudo and containers
Proxy settings that work in your terminal often vanish in automation, because each of these runs with a different environment. The safest pattern for scheduled jobs is a wrapper script that sets what it needs:
#!/bin/sh
# /usr/local/bin/nightly-fetch.sh, called from cron
export https_proxy="http://USER:[email protected]:PORT"
exec wget -q -T 30 --tries=3 -O /var/data/feed.xml https://partner.example.com/feed.xml- cron starts jobs with a minimal environment, so nothing from your shell profile applies. Export the variables in the script itself, or rely on the user's
~/.wgetrc. - sudo usually resets the environment. Use
sudo -Efor a one-off, or add the proxy names toenv_keepin sudoers; root's own~/.wgetrcis another option. - Docker builds accept
http_proxyandhttps_proxyas predefined build arguments, sodocker build --build-arg https_proxy=...reachesRUN wgetlines. Runtime containers need the variables passed with-e; see the Docker proxy setup. - Fedora and some newer distributions ship wget2 as
wget. Its option set differs in places, so checkwget --versionand the local man page if a flag is rejected.
A fixed exit IP for server downloads
A nightly fetch like the one above is the common reason to give wget a proxy: a partner feed, license server or vendor download area that only serves registered addresses. That works only if the address stays put. A ProxyV4 private datacenter IPv4 is assigned to one tenant for the whole term and keeps the same IP when you renew before expiry, and traffic on it is never metered, so large nightly downloads do not change what you pay. For the rest of the server setup, the Ubuntu proxy guide shows system-wide settings for apt and the shell.
Every proxy supports HTTP(S) and SOCKS5 with username and password, and per order you choose HTTP only, SOCKS5 only or both on the same port; for wget, make sure HTTP is enabled. Changing the mode can move the proxy to a new port, so update wgetrc afterwards. It is the wrong choice if the target serves only mobile carrier IPs or if you need a new IP per download, since rotating proxies are not on sale. IPv6 proxies are a separate product that only works on IPv6-ready sites, but private IPv4 reaches any IPv4 or dual-stack server. Order one IP from live pricing and test the real download first. If a proxy fails for a technical reason, the refund policy credits your balance.
Reading wget's proxy errors
wget prints each stage of the connection, so the line just before the error tells you how far it got.
Proxy request sent, awaiting response... 407 Proxy Authentication Requiredon anhttp://URL: wrong or missing credentials. Checkproxy_userandproxy_passwordfor typos and stray whitespace.Proxy tunneling failed: Proxy Authentication Requiredfollowed byUnable to establish SSL connection.on anhttps://URL: the same login problem during theCONNECTstep. The 407 error guide covers less obvious causes.Connecting to 203.0.113.10:PORT... failed: Connection refused.: wrong port, an order set to SOCKS5 only, or a mode change that moved the port.Error parsing proxy URL ...: Bad port number.: usually an unencoded:or@in the password inside the URL.- No error, but the download leaves from your own IP:
use_proxyis off, the variable is uppercase only, orno_proxymatched the host. Run with-dto see which proxy wget picked.
Frequently asked questions
Does wget support SOCKS5 proxies?
GNU wget does not. Use the proxy's HTTP mode, download with curl -x socks5h://..., or wrap wget with proxychains-ng.
Why does wget ignore my HTTPS_PROXY variable?
wget documents the lowercase names, and not every build reads the uppercase ones. Export https_proxy in lowercase and make sure use_proxy is not off.
Should https_proxy start with http:// or https://?
With a normal HTTP proxy, use http://. The HTTPS part refers to the sites you download, which wget reaches through a CONNECT tunnel.
Where should I store the proxy password for wget on a server?
In ~/.wgetrc of the account that runs the job, with permissions set to 600. That keeps it out of the process list, shell history and the scripts in version control.
Do I pay for the traffic my downloads use?
Not with ProxyV4 private IPv4 or static ISP proxies: traffic is not metered or billed, and you pay per IP for the term you choose.
Server downloads through a fixed IP
Give wget, curl and apt one private IPv4 that keeps its address on renewal, with HTTP(S) and SOCKS5 login and unmetered traffic. Order a single IP and test your real download first.
Try one private IP