Changing the User-Agent string for wget requests helps reproduce client-specific behavior, validate server-side filtering, and test bot detection rules without leaving the command line. Some web services vary responses based on the reported client, so controlling the user agent is a reliable way to confirm whether a response difference is caused by server logic or by downstream network tooling.
The wget client sends a default User-Agent header such as Wget/1.21.4 with each HTTP request. Override it per invocation with --user-agent or define a persistent default in /$HOME/.wgetrc. Using an explicit string keeps audit logs consistent and allows scoped overrides for one-off tests without impacting unrelated automation.
Misrepresenting automated clients as mainstream browsers can violate service policies and trigger blocks. If a service requires identification, use a truthful custom string and keep the scope of overrides limited to the specific testing session.
Steps to change the user agent in wget:
- Send a request with the default wget user agent and capture the echoed headers.
$ wget --no-config --output-document=ua-default.json --post-data=ping=ok https://www.example.com/post --2026-01-10 04:50:13-- https://www.example.com/post Resolving www.example.com (www.example.com)... 203.0.113.50 Connecting to www.example.com (www.example.com)|203.0.113.50|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 92 [application/json] Saving to: 'ua-default.json' 0K 100% 6.38M=0s 2026-01-10 04:50:13 (6.38 MB/s) - 'ua-default.json' saved [92/92]The --no-config flag ignores any existing /.wgetrc entries so the default user agent is visible.
- Override the user agent for a single request using --user-agent.
$ wget --no-config --user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36" --output-document=ua-custom.json --post-data=ping=ok https://www.example.com/post --2026-01-10 04:50:19-- https://www.example.com/post Resolving www.example.com (www.example.com)... 203.0.113.50 Connecting to www.example.com (www.example.com)|203.0.113.50|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 92 [application/json] Saving to: 'ua-custom.json' 0K 100% 6.52M=0s 2026-01-10 04:50:19 (6.52 MB/s) - 'ua-custom.json' saved [92/92]Some services block or rate-limit requests that claim to be browsers; use overrides responsibly and within policy.
- Configure a persistent default in /$HOME/.wgetrc for scripts or recurring jobs.
$ printf "user_agent = %s\n" "WgetCustom/1.0 (+https://www.example.com)" >> ~/.wgetrc $ grep -n '^user_agent' ~/.wgetrc | tail -n 1 4:user_agent = WgetCustom/1.0 (+https://www.example.com)
The user_agent directive affects all future wget calls for the current user unless overridden by --user-agent.
- Verify that the configured user agent is used without additional flags.
$ wget --output-document=ua-config.json --post-data=ping=ok https://www.example.com/post --2026-01-10 04:50:33-- https://www.example.com/post Resolving www.example.com (www.example.com)... 203.0.113.50 Connecting to www.example.com (www.example.com)|203.0.113.50|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 92 [application/json] Saving to: 'ua-config.json' 0K 100% 5.69M=0s 2026-01-10 04:50:33 (5.69 MB/s) - 'ua-config.json' saved [92/92]Successful verification is indicated by the echoed User-Agent string matching the value in /$HOME/.wgetrc.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
