Cookies are small data files that websites store on a user's device to remember information such as login status, preferences, or session details. They help websites provide a consistent and personalized user experience across multiple visits or page loads.
Sending cookies is useful for replicating authenticated sessions, accessing protected resources, or simulating browser behavior during automated testing or API interactions.
In this tutorial, you will learn to send cookies using the cURL command.

Prerequisites
- A system running Linux.
- Access to the terminal.
- A user account with root privileges.
How to Store Cookies?
Storing cookies can help maintain a logged-in or authenticated state across multiple requests, especially on websites or APIs that use session management. Storing cookies is especially useful when performing automated testing, scraping content behind login pages, or working with APIs that require session persistence.
On Linux, cURL allows you to store cookies in a text file by specifying the -c
flag. Follow the steps below:
1. Open the terminal.
2. Update the package repository information:
sudo apt update
3. If cURL is not installed on your system, install it with:
sudo apt install curl
4. Use the -c
(--cookie-jar
) option to store cookies in a file. For example:
curl -c cookies.txt https://example.com/login
cookies.txt
is the file in which you want to save the cookies.- Replace
https://example.com/login
with the address from which to download the cookies.
The command tells cURL to write any cookies received from the server into the specified file.
5. Verify that cookies were saved with ls:
ls -l
Note: Combine the -b
and -c
options to load existing cookies and save new or updated ones without truncating the jar. The syntax is:
curl -b cookies.txt -c cookies.txt https://site2.com
The command preserves existing cookies from site1.com, and adds new cookies from site2.com.
How to Send Cookies with cURL?
After storing cookies using cURL, you can reuse them to simulate an authenticated or consistent session when sending additional requests. This option is helpful for interacting with APIs or websites that require a login or tracking session data across multiple requests.
The following sections explain how to send cookies, format them, and remove them when no longer needed.
Cookie Format Used for Sending with cURL
When loading cookies from a file, cURL expects the file to follow the Netscape or JSON cookie jar formats, which include the following fields:
- Domain
- Path
- Expiration
- Cookie name/value pairs.
The command automatically uses the Netscape format when storing cookies with the -c
or --cookie-jar
option, so there is no need to modify the file manually.
To inspect the format, open the cookie file with cat:
cat cookies.txt
The output shows entries for each cookie, including fields like domain, path, expiration, and value. The example above shows the entry for httpbin.org.
Sending a Cookie
To send a single cookie stored in a file, use the -b
(--cookie
) option followed by the file path and the URL. For example:
curl -b cookies.txt https://example.com/dashboard
The command sends the request along with the cookies stored in cookies.txt, effectively continuing a session or simulating a logged-in state.
Sending Multiple Cookies
You can also manually specify one or more cookies directly in the command line using the -b
option followed by a string. For example:
curl -b "session_id=abc123; logged_in=true" https://example.com/dashboard
In this format:
- Multiple cookies are separated by semicolons.
- This method is useful for quick tests or when you do not need to persist cookies in a file.
Alternatively, combine -b
with -c
to load cookies from a file and save any updated ones received from the server:
curl -b cookies.txt -c cookies.txt https://example.com/dashboard
The command keeps your session cookies current across multiple requests.
How to Remove Stored Cookies?
To clear stored cookies, delete the cookie file from your system. The syntax is:
rm [path_to_file]
For example:
rm cookies.txt
The command removes all saved session data. Future cURL requests will not include any cookies unless you store new ones again.
Conclusion
This tutorial showed how to store, send, and remove cookies from your machine using cURL. Storing cookies with cURL is useful for maintaining session continuity across multiple requests, enabling automation of authenticated interactions with websites or APIs.
Next, learn how to send a cURL POST request or use cURL to show and send HTTP headers.