Curl - Basic authentication using the -u or --user option
by
Jeremy Canfield |
Updated: June 24 2022
| Curl articles
In this example, the foo.html page is being requested from the www.example.com web server.
curl https://www.example.com/foo.html
Let's say access to this page require basic authentication (username/password). The -u or --user option can be used to include a username and password in the request.
curl --user john.doe:itsasecret https://www.example.com/foo.html
Special Characters
Be aware that if the username or password contains special characters, such as an exclamation point . . .
curl --user john.doe:itsa!secret https://www.example.com/foo.html
Something like this will be returned.
-bash: !s: event not found
Special characters will need to be escaped, like like.
curl --user john.doe:itsa\!secret https://www.example.com/foo.html
Did you find this article helpful?
If so, consider buying me a coffee over at