Using cURL with a username and password?

user246114 picture user246114 · Apr 7, 2010 · Viewed 891.4k times · Source

I want to access a URL which requires a username/password. I'd like to try accessing it with curl. Right now I'm doing something like:

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

I get an error. I guess I need to specify a username and password along with the above command.

How can I do that?

Answer

Finbarr picture Finbarr · Apr 7, 2010

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