Skip to content

Instantly share code, notes, and snippets.

@jpawlowski
Last active May 6, 2022 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpawlowski/928937137a1f1abc5bcd9996089d99ce to your computer and use it in GitHub Desktop.
Save jpawlowski/928937137a1f1abc5bcd9996089d99ce to your computer and use it in GitHub Desktop.
Unattended generation of GnuPG / OpenPGP keys w/ ECC
#!/bin/sh
NAME='John Doe'
EMAIL='jdo@example.com'
export GNUPGHOME="$(mktemp -d)"
cat >$TMPDIR/gpg-gen.tmpl <<EOF
%echo Generating an OpenPGP key
Key-Type: eddsa
Key-Curve: ed25519
Key-Usage: sign
Subkey-Type: ecdh
Subkey-Curve: cv25519
Subkey-Usage: encrypt
Name-Real: $NAME
Name-Email: $EMAIL
Creation-Date: $(date +"%Y0101T000000")
Expire-Date: 455d
Passphrase: abcXYZ
# Do a commit here, so that we can later print "done" :-)
%commit
%echo done
EOF
gpg --batch --expert --full-gen-key $TMPDIR/gpg-gen.tmpl
gpg -a --command-fd 0 --pinentry-mode loopback --export-secret-keys > ./$EMAIL.asc <<EOF
abcXYZ
EOF
cp $GNUPGHOME/openpgp-revocs.d/*.rev ./$EMAIL.asc.rev
mkdir -p ./openpgpkey
gpg --list-options show-only-fpr-mbox -k $(echo $EMAIL | sed 's/^.*@/@/g') | gpg-wks-client -v --install-key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment