There are two ways in which you can perform basic auth using cURL,
- Using the -u or --user option
- Using the Authorization header in the request
Using the -u or --user option
In other to perform Basic Authentication using cURL command make use of -u or the --user option followed by user:password along with the cURL command request.
Syntax:curl -u <user-name:password> the-url
Example:% curl -u newuser:mypassword https://example.org
Note: If your username or password contains special characters, make sure the wrap the 'user:password' within single quotes.
Example: Basic Auth cURL with special character is user or password% curl -u 'new_user:my$password' https://example.org
Note: As the colon is used as a separator to distinguish the username and password, you cannot have a colon as a character in the username, but you can have it in the password string.
If you do not provide the password with the -u option and just provide the user, cURL will prompt you to enter the password.
Example: cURL Basic Auth with password prompt% curl -u newuser https://example.org
Enter host password for user 'newuser':

Perform Basic Auth by passing Authorization Header in cURL Request
The username:password string needs to be Base64-Encoded and passed in as a Header to your cURL request as below,
Plan text user:passwordmyuser:my$password
Base64 Encoded user:password
bXl1c2VyOm15JHBhc3N3b3Jk
cURL Example using Authorization Header
curl 'https://example.org' \
--header 'Authorization: Basic bXl1c2VyOm15JHBhc3N3b3Jk

Have Questions? Post them here!
- cURL Example using IP (IPv4 and IPv6) address and Port
- Efficient way to perform HTTP cURL GET/POST Requests with Payload
- Save cURL Command Output to a external file
- How to set Connection and Max Timeout for cURL Request with Examples
- [fix] command not found curl
- Fetch only content-type using cURL Command
- Trace using cURL Command Example
- Hide cURL Outputs and Errors on Terminal
- cURL Option to show HTTP Response Status Code
- Downloading Google Chrome using cURL Command
- Perform Basic Authentication using cURL with Examples
- List of 28 Protocols supported by cURL with Examples
- URL Encode cURL HTTP GET\POST Data with Examples
- Get the Size of HTTP Response using cURL Command (Content Length)
- How to get cURL Command to run in verbose mode?
- Get cURL command from Chrome Inspect Network HTTP URL
- Windows 10 now has a new enhanced Calculator with a new icon - News
- Mac - Open New Tab in Chrome Shortcut - Chrome
- How to disable button in Bootstrap - Bootstrap
- How to create Custom RatingBar Android Programming Tutorial - Android
- How to switch to Powershell on Mac Terminal - Powershell
- Install Bash Completion on macOS - Bash
- How to open a new tab in Notepad++ - NotepadPlusPlus
- [Solution] POI: Cannot get a NUMERIC value from a STRING cell - Java