Setting Up wget Behind a Proxy That Needs a Login

· 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.

Server downloads through a fixed IP

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-ip

The 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-ip

Stick 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%2Frd

Alternatively 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.example

The 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 command

Using 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.gz

The 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 PASS
sudo apt install proxychains4      # Debian/Ubuntu package name
proxychains4 -q wget https://example.com/file.tar.gz

proxy_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 -E for a one-off, or add the proxy names to env_keep in sudoers; root's own ~/.wgetrc is another option.
  • Docker builds accept http_proxy and https_proxy as predefined build arguments, so docker build --build-arg https_proxy=... reaches RUN wget lines. 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 check wget --version and 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 Required on an http:// URL: wrong or missing credentials. Check proxy_user and proxy_password for typos and stray whitespace.
  • Proxy tunneling failed: Proxy Authentication Required followed by Unable to establish SSL connection. on an https:// URL: the same login problem during the CONNECT step. 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_proxy is off, the variable is uppercase only, or no_proxy matched the host. Run with -d to 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

Related articles

Proxy setup
Configuring a Proxy on Ubuntu and Debian, Layer by Layer
Set an authenticated APT proxy on Ubuntu or Debian, then the shell, systemd services, sudo and GNOME. Copy-paste config files and checks that prove it works.
Proxy setup
Using cURL with an authenticated proxy: commands that prove it works
Send cURL requests through an authenticated HTTP(S) proxy with -x and -U, confirm the exit IP, read the CONNECT handshake and time each request on any OS.
Proxy setup
Running Docker containers behind an authenticated HTTP proxy
Send Docker container, build and image pull traffic through an authenticated HTTP(S) proxy, keep service-to-service calls local with NO_PROXY and verify the IP.
Products
Dedicated datacenter proxies: one private IPv4 per customer
Private IPv4 proxies in the US, Vietnam, Japan, South Korea, Singapore, the UK and Hong Kong. One tenant per IP, HTTP(S) and SOCKS5, no traffic metering.
Proxy setup
Set up your proxy, tool by tool
Proxy setup instructions you can follow with the dashboard open: antidetect browsers, operating systems, browser extensions and scraping libraries, all with authenticated HTTP(S) or SOCKS5.
Knowledge base
How to Run git clone Through a Proxy (HTTPS and SSH Remotes)
Git clone through a proxy: set http.proxy globally, per repo or per host, use socks5h for HTTPS remotes, and route git over SSH with a ProxyCommand.
Knowledge base
Using pip install Behind a Proxy, From One Command to a Saved Config
pip install through a proxy: the --proxy flag, pip.conf and pip.ini paths per OS, env vars, encoding passwords with special characters, and conda settings.
Knowledge base
Configuring npm, Yarn and pnpm to Install Packages Through a Proxy
npm config set proxy and https-proxy explained, plus Yarn classic, Yarn Berry and pnpm proxy keys, .npmrc precedence, SOCKS5 and safe settings for CI builds.
Free tools
Check proxies in bulk: status, exit IP and latency
Free online proxy checker: paste up to 100 ip:port:user:pass lines and see which proxies work, their exit IP and latency, plus what each failure result means.
Products
Static ISP proxies: residential IPs on consumer networks
Static ISP proxies in the United States and Vietnam: fixed IPs registered to consumer internet providers, rented to one customer, with unmetered traffic.