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?
To let the password least not pop up in your
.bash_history
:It is safer to do:
...as passing plain user/password string on the command line is a bad idea.
The format of the password file is (as per
man curl
):Note:
https://
or similar! Just the hostname.machine
', 'login
', and 'password
' are just keywords; the actual information is the stuff after those keywords.To securely pass the password in a script (i.e. prevent it from showing up with ps auxf or logs) you can do it with the -K- flag (read config from stdin) and a heredoc:
If you are on a system that has Gnome keyring app a solution that avoids exposing the password directly is to use gkeyring.py to extract the password from the keyring:
You can use command like,
Then HTTP password will be triggered.
Reference: http://www.asempt.com/article/how-use-curl-http-password-protected-site
pretty easy, do the below: