Method #1
We can use the -u flag to include a username, and curl will prompt for a password
curl -u username http://yoursite.com
Or even you can include the password in command
curl -u username:password http://yoursite.com
Method #2
Include the username and password as part of URL.
curl http://username:[email protected]/login
Method #3 (More Secure Method)
This is more secure way, as it won’t expose your secret details to other command line users.
1. Create a file my-password-file
2. Add the below in the file, replace your username, password and host
machine example.com login USERNAME password PASSWORD
Note:Machine name must not contain https://or any protocol. Host name only.
3. Now use the command like below
curl --netrc-file /home/my-password-file http://example.com
Did this post help you?
Tutsplanet brings in-depth and easy tutorials to understand even for beginners. This takes a considerable amount of work. If this post helps you, please consider supporting us as a token of appreciation:
- Just want to thank us? Buy us a Coffee
- May be another day? Shop on Amazon using our links.
Your prices won't change but we get a small commission.