How to Change the Default curl User-Agent

This article provides a quick guide on how to modify the default User-Agent string sent by the curl command-line tool. You will learn how to temporarily change the User-Agent for individual requests using command-line flags, as well as how to configure a permanent custom User-Agent for all future curl sessions.

By default, when you make a request using curl, it sends a User-Agent string that identifies the tool and its version (for example, curl/7.81.0). Some web servers block this default identifier or serve different content based on the browser. You can easily override this behavior using the methods below.

Method 1: Using the -A or --user-agent Flag

The fastest and most common way to change the User-Agent is by using the -A flag followed by your custom string in quotes.

curl -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" https://example.com

Alternatively, you can use the long-form flag --user-agent:

curl --user-agent "MyCustomUserAgent/1.0" https://example.com

Method 2: Using the -H or --header Flag

You can also modify the User-Agent by manually defining the User-Agent HTTP header using the -H flag. This method is useful if you are already passing multiple custom headers.

curl -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)" https://example.com

Method 3: Changing the Default User-Agent Permanently

If you want curl to use a custom User-Agent automatically every time you run a command without typing the flag, you can save it to your curl configuration file.

  1. Open (or create) the .curlrc file in your home directory:

    nano ~/.curlrc
  2. Add the following line to the file:

    user-agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
  3. Save and close the file. Any curl command you run from now on will use this specified User-Agent.