Skip to content

Instantly share code, notes, and snippets.

@spangey
Created December 30, 2015 20:50
Show Gist options
  • Save spangey/24140e8885673fbc82c1 to your computer and use it in GitHub Desktop.
Save spangey/24140e8885673fbc82c1 to your computer and use it in GitHub Desktop.
encryptPlainTxtAuthFilles
A very convenient feature of Curl is that if invoked with curl -n, it will try to read credentials
of a target service from a local .netrc file, and if found, use them for authentication. The trouble
is that these credentials default to being stored in plain text, which is something that we’d like to avoid by using GPG.
The first step here is to encrypt your .netrc:
$ gpg -r <your email> -e ~/.netrc
$ ls ~/.netrc.gpg
$ rm ~/.netrc
Now we can can pipe the decrypted output of our .netrc file from gpg, and have Curl read it in (this should go in your appropriate *rc file):
$ alias curl="gpg --batch -q -d ~/.netrc.gpg | curl --netrc-file /dev/stdin"
Because we’ve folded this into an alias, curl can be invoked normally:
$ curl -n https://api.heroku.com/apps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment