How to Use curl with Username and Password for Secure API Authentication?

9 Replies, 2169 Views

Hey! I had the same issue when I started using curl with username and password. What worked for me was using a `.netrc` file. You can store your credentials there, and curl will pick them up automatically.

Create a `.netrc` file in your home directory:
```bash
machine api.example.com
login username
password password
```
Then use curl like this:
```bash
curl -n https://api.example.com
```
This keeps your credentials out of the command line entirely.

Messages In This Thread



Users browsing this thread: 1 Guest(s)