Documentation Python quickstart Blog Free tools Enterprise solutions hello@quanticdata.ioLog in

curl basic auth: -u user:password, the Authorization header and proxy logins

How curl sends basic authentication: -u ada:s3cret becomes the header Authorization: Basic YWRhOnMzY3JldA==, which is only the base64 of ada:s3cret; the server answers 200 with authenticated true, or 401 with WWW-Authenticate when the password is wrong; the card shows that the site login goes in -u and the proxy login in -U.
How curl sends basic authentication: -u ada:s3cret becomes the header Authorization: Basic YWRhOnMzY3JldA==, which is only the base64 of ada:s3cret; the server answers 200 with authenticated true, or 401 with WWW-Authenticate when the password is wrong; the card shows that the site login goes in -u and the proxy login in -U.

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

CommandStatusWhat else came back
curl -u ada:s3cret URL200"authenticated": true
curl -u ada:wrong URL401www-authenticate: Basic realm="Fake Realm"
curl URL (no credentials)401Same challenge
curl -u ada URLwaitscurl 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

PasswordCommand that worked
pa:ss (a colon)curl -u 'ada:pa:ss' URL: curl splits at the first colon only
p@ss with -ucurl -u 'ada:p@ss' URL: no encoding needed
p@ss inside the URLcurl '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, UScorrectcorrect"authenticated": true
Mobile, UScorrectcorrect"authenticated": true
Residential Premium, Germanycorrectcorrect"authenticated": true
Residential Basic, http:// URLwrong passwordnone407 from the proxy
Residential Basic, https:// URLwrong passwordnonecurl: (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.

Sources & further reading

FAQ

Quick answers on curl basic auth.

Something else? Ask us

How do I use basic auth with curl?

Use curl -u username:password URL. curl base64-encodes the pair and sends it as Authorization: Basic .... In our test, -u ada:s3cret sent Authorization: Basic YWRhOnMzY3JldA== and the server answered 200.

How do I send a basic auth header in curl?

Either let -u build it, or send it yourself: curl -H "Authorization: Basic $(printf 'user:pass' | base64)" URL. Both give the same header; use printf so no newline is encoded.

How do I make curl ask for the password?

Give only the username: curl -u ada URL. curl prints Enter host password for user 'ada': and waits, so the password never appears in the command or in your shell history.

How do I use a password with special characters in curl?

With -u, quote the pair: -u 'ada:p@ss' worked, and so did a colon (-u 'ada:pa:ss'), because curl splits at the first colon. Inside a URL, percent-encode the character: p%40ss for p@ss.

What is the difference between curl -u and -U?

-u logs in to the site, -U logs in to the proxy set with -x. A wrong -u gives 401 from the site; a wrong -U gives 407 from the proxy, or "CONNECT tunnel failed, response 407" (exit 7) for an https URL.

Is curl basic auth secure?

Only over https. The header is base64, which anyone who sees it can decode back to the password. Over https it travels encrypted; over plain http it does not.

Authenticated proxies for authenticated APIs

Residential and mobile proxies with username and password login, country targeting and sticky sessions, ready for curl -x and -U.

Related reading