To send HTTP basic authentication with curl, use -u: curl -u username:password https://example.com/. curl joins the two with a colon, base64-encodes them and sends Authorization: Basic .... Give only the username (-u username) and curl asks for the password, so it stays out of your shell history.
We ran every command below on 20 November 2026 with curl 8.22.0 on Windows 11, against httpbin.org's test endpoints, which accept a username and password you choose in the URL (here ada and s3cret), and through QuanticData proxies.
Basic auth with -u
$ curl -u ada:s3cret https://httpbin.org/basic-auth/ada/s3cret
{
"authenticated": true,
"user": "ada",
"authorized": true
}
--user is the long form of -u. Basic is the scheme -u uses unless you ask for another one, as the digest test further down shows.
The header curl sends, and building it by hand
-v shows the request headers. The Authorization line is all that -u adds:
$ curl -sv -u ada:s3cret https://httpbin.org/basic-auth/ada/s3cret -o /dev/null 2>&1 | grep -E "^> Authorization|^< HTTP"
> Authorization: Basic YWRhOnMzY3JldA==
< HTTP/1.1 200 OK
That value is ada:s3cret in base64. You can build the same header yourself, for tools that only take headers:
$ printf 'ada:s3cret' | base64
YWRhOnMzY3JldA==
$ curl -H "Authorization: Basic YWRhOnMzY3JldA==" https://httpbin.org/basic-auth/ada/s3cret
{
"authenticated": true,
...
}
Use printf, not echo: echo adds a newline, which gets encoded too (YWRhOnMzY3JldAo=), and the server answered 401 to that header. And because base64 decodes back to the password in one step, basic auth must only travel over https.
Wrong password, no password: 401
| Command | Status | What else came back |
|---|---|---|
curl -u ada:s3cret URL | 200 | "authenticated": true |
curl -u ada:wrong URL | 401 | www-authenticate: Basic realm="Fake Realm" |
curl URL (no credentials) | 401 | Same challenge |
curl -u ada URL | waits | curl printed Enter host password for user 'ada': |
curl exits 0 on a 401 unless you add -f, so scripts should read the status with -w "%{http_code}" or use -f. The www-authenticate header names the scheme the server wants; -D - -o /dev/null prints it:
$ curl -sS -o /dev/null -w "%{http_code}\n" -u ada:wrong https://httpbin.org/basic-auth/ada/s3cret
401
$ curl -sS -D - -o /dev/null -u ada:wrong https://httpbin.org/basic-auth/ada/s3cret | grep -i "www-authenticate"
access-control-expose-headers: Retry-After, RateLimit, RateLimit-Policy, WWW-Authenticate
www-authenticate: Basic realm="Fake Realm"
"Basic" in that header means -u as shown here is the right tool. Other servers want another scheme: on the digest endpoint further down, -u alone got 401 and --digest worked. The realm is only a label for the protected area; curl does not need it.
Special characters in the password
| Password | Command that worked |
|---|---|
pa:ss (a colon) | curl -u 'ada:pa:ss' URL: curl splits at the first colon only |
p@ss with -u | curl -u 'ada:p@ss' URL: no encoding needed |
p@ss inside the URL | curl 'https://ada:p%40ss@httpbin.org/...': encode @ as %40 |
Put the pair in single quotes in bash so the shell leaves $, ! and spaces alone. Credentials in the URL (https://ada:s3cret@host/) also worked, but they end up in logs and history more easily than -u.
Keeping the password out of the command: .netrc
$ cat netrc.txt
machine httpbin.org login ada password s3cret
$ curl --netrc-file netrc.txt https://httpbin.org/basic-auth/ada/s3cret
{
"authenticated": true,
...
}
One line per host. --netrc-file reads the file you name; keep it readable only by your user. Together with the prompt of -u ada, it is the way to keep passwords out of scripts and shell history.
Digest and --anyauth
Some servers ask for digest authentication instead of basic. Sending basic to a digest endpoint returned 401; --digest fixed it, and so did --anyauth, which lets curl ask the server and pick the scheme:
curl --digest -u ada:s3cret https://httpbin.org/digest-auth/auth/ada/s3cret # authenticated: true
curl --anyauth -u ada:s3cret https://httpbin.org/digest-auth/auth/ada/s3cret # authenticated: true
Site login and proxy login on one command
Basic auth also exists one hop earlier: an authenticated proxy wants its own username and password. curl keeps the two apart: -u is for the site, -U (or --proxy-user) is for the proxy. We sent both at once through three QuanticData networks:
curl -x http://residentialboson.quanticdata.io:10000 -U "USER-type-residential-country-us-session-ca01-lifetime-30:PASS" -u ada:s3cret https://httpbin.org/basic-auth/ada/s3cret
curl -x http://mobile.quanticdata.io:8080 -U "USER-country-us-type-mobile-sid-ca03-ttl-30m:PASS" -u ada:s3cret https://httpbin.org/basic-auth/ada/s3cret
curl -x http://residentialpremium.quanticdata.io:8080 -U "USER-country-de-sid-ca02-ttl-30m:PASS" -u ada:s3cret https://httpbin.org/basic-auth/ada/s3cret
| Network | -U (proxy) | -u (site) | Result |
|---|---|---|---|
| Residential Basic, US | correct | correct | "authenticated": true |
| Mobile, US | correct | correct | "authenticated": true |
| Residential Premium, Germany | correct | correct | "authenticated": true |
| Residential Basic, http:// URL | wrong password | none | 407 from the proxy |
| Residential Basic, https:// URL | wrong password | none | curl: (7) CONNECT tunnel failed, response 407 |
The status code tells you which login failed: 401 comes from the site (check -u), 407 from the proxy (check -U). Our guide to 407 Proxy Authentication Required goes through the proxy side, and how to use a proxy with curl covers gateways and SOCKS5.
Basic auth with a POST
-u combines with any request. curl -u ada:s3cret --json '{"a":1}' https://httpbin.org/anything arrived as a POST with "Authorization": "Basic YWRhOnMzY3JldA==" and the JSON body {"a": 1}. The body options are in curl POST requests.
When your scripts call protected APIs from a set country, our residential proxies and mobile proxies take the -x and -U options above; there is a Residential Basic free trial.


