Customizing the User-Agent header in cURL enables controlled testing of server behavior with different clients. Many web applications vary responses based on the reported browser, device, or bot identity, so sending a specific user agent helps reproduce client-specific issues and validate compatibility.

During an HTTP request, cURL automatically adds a User-Agent header such as curl/8.1.2 if none is specified. The header travels with the request line and other headers, and origin servers log and sometimes route traffic based on this value. Overriding the header at the command line or configuring a default in ~/.curlrc provides precise control over what each request advertises.

Altering the User-Agent header can influence rate limits, bot detection, and access policies, and some providers forbid misrepresenting automated clients as mainstream browsers. A globally overridden user agent may also hide the presence of cURL in logs or break scripts that depend on the default identifier. For most workflows, a temporary override per command keeps behavior predictable while still enabling focused testing.

Steps to change the user agent string in cURL:

  1. Open a terminal session that has access to cURL.
    $ whoami
    root

    When possible, run cURL as an unprivileged account to limit the impact of misconfigured scripts or unexpected responses.

  2. Inspect the default User-Agent header using a verbose request to a test URL.
    $ curl "https://example.com" --verbose --silent
    ##### snipped #####
    > User-Agent: curl/8.5.0
    ##### snipped #####

    The line beginning with > User-Agent: in verbose output shows the exact identifier transmitted in the request.

  3. Override the User-Agent header for a single request using --user-agent.
    $ curl --user-agent "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0" "https://example.com" --verbose --silent
    ##### snipped #####
    > User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0
    ##### snipped #####

    The --user-agent option sets the header for that invocation only and leaves global configuration unchanged.

  4. Override the header explicitly using --header "User-Agent: …" when constructing requests with multiple custom headers.
    $ curl --header "User-Agent: Mozilla/5.0 (compatible; CustomClient/1.0)" --header "X-Debug-Trace: 1" "https://example.com" --verbose --silent
    ##### snipped #####
    > User-Agent: Mozilla/5.0 (compatible; CustomClient/1.0)
    > X-Debug-Trace: 1
    ##### snipped #####

    Using --header sends each header exactly as written and replaces the automatic User-Agent generated by cURL.

  5. Configure a persistent default user agent for all cURL commands in ~/.curlrc.
    $ echo 'user-agent = "Mozilla/5.0 (compatible; CustomClient/1.0)"' >> ~/.curlrc

    Appending a global user-agent setting can confuse log analysis, breach service policies that expect cURL identification, or disrupt scripts that assume the built-in default.

  6. Verify that subsequent requests send the configured user agent instead of the default string.
    $ curl "https://example.com" --verbose --silent
    ##### snipped #####
    > User-Agent: Mozilla/5.0 (compatible; CustomClient/1.0)
    ##### snipped #####

    Successful configuration is indicated when verbose output and remote logs consistently show the custom value in the User-Agent field.

Discuss the article:

Comment anonymously. Login not required.