Connect to a service (HTTP)¶
Create a .netrc file¶
Note
Many services are protected by Basic authentication. When accessing these services in a web browser, you typically need to enter your credentials only once, and your browser will submit the Authorization header on subsequent requests. When accessing these services from the command line, you typically need to enter your credentials every time. Creating and using a .netrc file on your computer avoids this extra work.
To create (or append credentials to) a ~/.netrc file:
Run, replacing
HOSTNAMEwith the server’s hostname (e.g.ocp99.open-contracting.org),USERNAMEwith your username, andPASSWORDwith your password:echo 'machine HOSTNAME login USERNAME password PASSWORD' >> ~/.netrc
Check that only one section of the
~/.netrcfile refers to the hostname, replacingHOSTNAME:$ grep -A2 HOSTNAME ~/.netrc machine myhostname login myuser password mypass
If there are multiple sections or an incorrect password, you must correct the file in a text editor.
Change the file’s permissions to be readable only by the owner:
chmod 600 ~/.netrc
Check the permissions:
$ stat -f "%Sp" ~/.netrc -rw-------
Test your configuration. For example, for Kingfisher Collect:
$ curl -n https://collect.kingfisher.open-contracting.org/listprojects.json {"node_name": "ocp99", "status": "ok", "projects": ["kingfisher"]}