The User-Agent header identifies the client’s software, device, or platform. By default, cURL announces itself, but changing this header can simulate various browsers or clients.
Altering the User-Agent broadens testing scenarios, enabling examination of server responses tailored to mobile devices, different browser versions, or other user agents. It also helps bypass simple filters that reject default cURL identifiers.
By customizing the user agent, you can explore conditional content delivery, test compatibility, and ensure the server meets diverse client requirements.
Steps to change the user agent string in cURL:
- Open a terminal.
- Check the default User-Agent with --verbose.
$ curl "http://www.example.com" --verbose > User-Agent: curl/8.1.2
- Change the User-Agent using --user-agent.
$ curl --user-agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0" "http://www.example.com" --verbose > User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0
Mimicking a browser’s user agent can produce different server responses.
- Alternatively, set the User-Agent with --header.
$ curl --header "User-Agent: Mozilla/5.0 ..." "http://www.example.com" --verbose
Using --header is another method to alter headers.
- Permanently define a User-Agent in ~/.curlrc.
$ echo 'user-agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; ...)"' >> ~/.curlrc
All future cURL requests use this user agent by default.
- Verify the changed User-Agent in subsequent requests.
$ curl "http://www.example.com" --verbose > User-Agent: Mozilla/5.0 ...
Confirm that the desired user agent is now sent.

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.
Comment anonymously. Login not required.