Reputation: 36214
Once gpg installed and configured, it can be used for variety of things. I even learned how to keep arbitrary data encrypted for my applications, I can easily do something like this:
gpg2 -q --for-your-eyes-only --no-tty -d ~/my-encrypted-file.gpg
One thing I can't figure out though, there's gotta be an idiomatic way of retrieving passwords from authinfo.gpg, right?
So let's say I want to have a script that mounts an external drive to some remote machine (let's call it 'beefy-server'), but I don't want to expose the uname/password. If I keep it encrypted in authinfo.gpg in standardized form:
machine beefy-server login admin password foobar1030
I can of course, do:
gpg2 -q --for-your-eyes-only --no-tty -d ~/.authinfo.gpg
and then pipe it to awk, sed and whatnot, right now I'm doing it like this:
gpg2 -q --for-your-eyes-only --no-tty -d ~/.authinfo.gpg \
| grep beefy-server \
| sed -e "s/.*password\(.*\).*$/\1/"
But is there a better way?
Upvotes: 2
Views: 735
Reputation: 573
I think that the conventioned way to pipe gpg output through awk is
gpg2 -q --for-your-eyes-only --no-tty -d ~/.authinfo.gpg | awk '/machine beefy-server login yourname/ {print $NF}'
where it is assumed that you have a line in authinfo.gpg that has details of the beefy-server and the password at the end. Like so
machine beefy-server login yourname port 465 password myverysecretpassword
Upvotes: 3