Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quickly start signing GitHub git commits - GPG Key Generation, global automatic commit signing
# I am using WSL2 on Windows 10
# Generate GPG key
gpg --full-generate-key
# List keys, find the one you just made and grab the key id
gpg --list-secret-keys --keyid-format LONG
# OUTPUT
# sec rsa4096/1124F0AFF0B78C69 2019-10-16 [SC] # LONG key id in this case is 1124F0AFF0B78C69
# A2EE26D553256FC123A7D8EE1524F0AFF0B78C69
# uid [ultimate] John Doe (GitHub GPG key for signing commits) <jdoe@example.com>
# ssb rsa4096/6141459916605DA8 2019-10-16 [E]
# Export the public key and add it to GitHub
gpg --armor --export 1124F0AFF0B78C69 > github_gpg_rsa.pub
# List keys, find the one you just made and grab the key id
gpg --list-secret-keys --keyid-format SHORT
# OUTPUT
# sec rsa4096/F0C78C69 2019-10-16 [SC] # SHORT key id in this case is F0C78C69
# A1EE26D553256FC123A7D8EE1524F0AFF0B78C69
# uid [ultimate] John Doe (GitHub GPG key for signing commits) <jdoe@example.com>
# ssb rsa4096/12605DA8 2019-10-16 [E]
# Configure git globally with your SHORT id so it knows which GPG key to use
git config --global user.signingkey F0C78C69
# This will force git to sign every commit automatically
git config --global commit.gpgsign true
# If GPG fails to sign the commit after you test it, you may need to do something like this
export GPG_TTY=$(tty)
Resources:
https://gist.github.com/mort3za/ad545d47dd2b54970c102fe39912f305
https://help.github.com/en/articles/signing-commits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment