How to change the user agent string in cURL

Changing the User-Agent header in cURL helps reproduce browser-specific responses, test upstream allow lists, and label scripted traffic with a clearer client name. The quickest path is usually a one-request override so the change stays attached to the exact call being tested.

By default, cURL sends its own identifier as curl/<version>. The -A or --user-agent option replaces that value for one request, while a user-agent entry in ~/.curlrc changes the default used by later commands from the same account.

Some services use User-Agent for policy checks, caching decisions, or bot controls. Keep one-off overrides narrow, and save a default only when later requests should all present the same identity.

Steps to change the cURL User-Agent string:

  1. Check the built-in User-Agent first so the comparison starts from the default cURL identity.
    $ curl -q --silent --show-error https://httpbingo.org/user-agent
    {
      "user-agent": "curl/8.7.1"
    }

    -q ignores the default startup file for that run, so the response shows the built-in header instead of a saved override from ~/.curlrc.

  2. Override the header for one request with --user-agent when only that call should change.
    $ curl -q --silent --show-error --user-agent 'ExampleInventoryClient/2026.04' https://httpbingo.org/user-agent
    {
      "user-agent": "ExampleInventoryClient/2026.04"
    }

    Use -A or --user-agent instead of building a raw User-Agent: header manually when that is the only header being changed.

  3. Confirm the exact outbound header with --verbose when the server response alone is not enough.
    $ curl -q --silent --show-error --verbose --output /dev/null --user-agent 'ExampleInventoryClient/2026.04' https://httpbingo.org/user-agent
    ##### snipped #####
    > GET /user-agent HTTP/2
    > Host: httpbingo.org
    > User-Agent: ExampleInventoryClient/2026.04
    > Accept: */*
    >
    ##### snipped #####

    The > lines are the request headers sent by cURL.

  4. Add a default user-agent entry to ~/.curlrc when later cURL commands from that account should all use the same value.
    ~/.curlrc
    user-agent = "ExampleInventoryClient/2026.04"

    If ~/.curlrc already contains a user-agent line, replace that entry instead of stacking a second default. A saved value affects later HTTP requests until the file is changed, bypassed with -q, or overridden on the command line.

  5. Run a normal request without -q and confirm that the saved default is now active.
    $ curl --silent --show-error https://httpbingo.org/user-agent
    {
      "user-agent": "ExampleInventoryClient/2026.04"
    }