Skip to content

Instantly share code, notes, and snippets.

@pretorh
Created September 30, 2018 08:31
Show Gist options
  • Save pretorh/0a4a8192e0b8e8c9a7b574ec1c824224 to your computer and use it in GitHub Desktop.
Save pretorh/0a4a8192e0b8e8c9a7b574ec1c824224 to your computer and use it in GitHub Desktop.
GPG test environment

creating:

GNUPGHOME=${GNUPGHOME?'need path for new gnupg home dir'}
GPG_PASS_PHRASE=${GPG_PASS_PHRASE-passphrase}

# refuse to overwrite existing
if [ -e "$GNUPGHOME" ] ; then
    echo "$GNUPGHOME already exists!"
    exit 1
fi

# create the directory, set permissions
mkdir -pv "$GNUPGHOME"
chmod 700 "$GNUPGHOME"

# create a secret key
export GNUPGHOME
cat << EOF | gpg --batch --gen-key
Key-Type: RSA
Name-Email: foo@bar.com
Passphrase:$GPG_PASS_PHRASE
EOF

using: make sure GNUPGHOME env var is set, and add --passphrase=$GPG_PASS_PHRASE --batch --pinentry-mode loopback to gpg options

ex echo "hello" | gpg --armor --sign --passphrase=passphrase --batch --pinentry-mode loopback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment