Skip to content

Instantly share code, notes, and snippets.

@dzmitry-lahoda
Forked from o-az/github-gpg-sign.md
Last active December 20, 2022 13:13
Show Gist options
  • Save dzmitry-lahoda/597002a7939730579fd96ddb2801c8b8 to your computer and use it in GitHub Desktop.
Save dzmitry-lahoda/597002a7939730579fd96ddb2801c8b8 to your computer and use it in GitHub Desktop.

Generate gpg key and add it to your GitHub account for commit signing & verification

Step 1 (Skip this if you already have GitHub CLI and GnuPG installed)

Install GnuPG and GitHub official CLI tool. Instructions:

# If you're using macOS and Homebrew
brew update && brew upgrade

brew install gnupg gh
# MacOs or Linux
nix profile install nixpkgs#gh nixpkgs#gnupg nixpkgs#pinentry-curses 

In case of pinentry error, restart your gpg-agent with path to pinentry.

Step 2 (Skip this if you are already auth'd for GitHub CLI)

gh auth login
# Follow remaining steps to auth GitHub CLI

Step 3

Generate gpg key

gpg --full-generate-key

Options I selected:

  • Select 1

  • 4096 bits long

  • Expires in: 1y

__

  • name: YOUR GITHUB NAME (important)
  • email: YOUR GITHUB EMAIL (important)
  • Comment: optional (I didn't add anything)
  • Passphrase (optional but you should)

Get your public key info info

gpg --list-secret-keys --keyid-format=long
sec   rsa4096/[THIS_KEY_ID] 2021-07-07 [SC]
      2B18EEB732D15480D40A60D605AE1785E201CE95
uid                 [ultimate] Jon Die <[email protected]>
ssb   rsa4096/C98A99F6B0202433 2021-07-07 [E]

Copy [THIS_KEY_ID] (it should be 16 digits)

For details https://docs.github.com/en/authentication/managing-commit-signature-verification/associating-an-email-with-your-gpg-key

Step 4

Save public key to a file

mkdir ~/public-keys

gpg --armor --export THIS_KEY_ID > ~/public-keys/GITHUB_GPG_PUBLIC_KEY.gpg

Let GitHub know about your key

gh auth refresh --scopes write:gpg_key 
gh gpg-key add ~/public-keys/GITHUB_GPG_PUBLIC_KEY.gpg

Step 5

Peek up new GPG key as signing in git(based on https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key)

``sh git config --global --unset gpg.format git config --global user.signingkey THIS_KEY_ID git config --global commit.gpgsign true


## Step 6

Sign some commit on your account (may be crev-prove) 
``
gpg --amend --gpg-sign

Publish to keyservers

 gpg --send-keys THIS_KEY_ID

(as per https://security.stackexchange.com/questions/181208/sending-the-gpg-key-to-keyserver )

Optionally can set gpg on your Kusama Identity.

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