These curl recipes show you how to perform basic HTTP server authorization. To do that, use the -u user:pass command line argument. If you skip the password (but leave the colon), then no password is set. If you also skip the colon, then curl prompts for the password.

Set the Username and Password via the -u Argument

curl -u 'bob:12345' https://google.com/login

This recipe uses the -u 'bob:12345' argument to set the username to bob and password to 12345. This username and password is then base64-encoded by curl and sent to the server at https://google.com/login in the Authorization HTTP header. For the username and password bob:12345, this header is set to Authorization: Basic Ym9iOjEyMzQ1.

Set the Username and Password in the URL

curl https://bob:12345@google.com/login

This recipe puts the username and password bob:12345 in the URL itself. Curl is smart enough to figure it out and it does exactly the same as in the previous recipe, and performs the basic HTTP authentication with this username and password.

Use an Empty Password

curl -u 'bob:' https://google.com/login

This recipe only sets the username part user: of user:pass and doesn't specify the password. In this case, the password is empty. If the web server allows passwordless users, then this request will succeed, otherwise it will fail.

Make Curl Prompt for the Password

curl -u 'bob' https://google.com/login

This recipe skips the password part altogether (including the colon). In this case, curl asks for the password on the command line. This is useful if you don't want the password to be saved in the shell history.

Created by Browserling

These curl recipes were written down by me and my team at Browserling. We use recipes like this every day to get things done and improve our product. Browserling itself is an online cross-browser testing service powered by alien technology. Check it out!

Secret message: If you love my curl recipe, then I love you, too! Use coupon code CURLLING to get a discount at my company.