Using cURL with a username and password? Using cURL with a username and password? curl curl

Using cURL with a username and password?


Use the -u flag to include a username, and curl will prompt for a password:

curl -u username http://example.com

You can also include the password in the command, but then your password will be visible in bash history:

curl -u username:password http://example.com


It is safer to do:

curl --netrc-file my-password-file http://example.com

...as passing a plain user/password string on the command line, is a bad idea.

The format of the password file is (as per man curl):

machine <example.com> login <username> password <password>

Note:

  1. Machine name must not include https:// or similar! Just the hostname.
  2. The words 'machine', 'login', and 'password' are just keywords; the actual information is the stuff after those keywords.


Or the same thing but different syntax

curl http://username:password@api.somesite.com/test/blah?something=123