Skip to content

Instantly share code, notes, and snippets.

@h0tw1r3
Last active September 17, 2024 15:43
Show Gist options
  • Save h0tw1r3/818f34122863eb97dcd26e104e9cfb63 to your computer and use it in GitHub Desktop.
Save h0tw1r3/818f34122863eb97dcd26e104e9cfb63 to your computer and use it in GitHub Desktop.
Generate GPG key for signing packages, export keys and generate public keyring
#!/bin/sh
set -eo nounset
export GNUPGHOME="$(mktemp -d)"
trap 'cleanup' EXIT
cleanup() { rm -Rf "$GNUPGHOME" ; }
export NAME_REAL="Signing Key"
export NAME_EMAIL="sign@local"
cat <<EOF > "$GNUPGHOME/genkey.batch"
%echo Generating a OpenPGP key
Key-Type: RSA
Key-Length: 4096
Key-Usage: sign
Name-Real: ${NAME_REAL}
Name-Email: ${NAME_EMAIL}
Expire-Date: 0
%no-ask-passphrase
%no-protection
%commit
%echo done
EOF
gpg --no-tty --batch --gen-key "$GNUPGHOME/genkey.batch"
gpg --armor --export "${NAME_REAL}" > public.asc
gpg --armor --export-secret-keys "${NAME_REAL}" > private.asc
gpg --show-keys --with-subkey-fingerprint public.asc
gpg --no-default-keyring --keyring="${GNUPGHOME}/keyring.gpg" --batch --import "${PWD}/public.asc" && \
gpg --no-default-keyring --keyring="${GNUPGHOME}/keyring.gpg" --batch --output "${PWD}/keyring.gpg" --export --yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment