You are currently viewing Setup Verified Git Commit in MacOSX

Setup Verified Git Commit in MacOSX

Here we go...

  1. Install the required packages.
$ brew install gpg2 pinentry-mac
  1. Generate a GPG key pair.
$ gpg --full-generate-key
  1. Press Enter to use the default RSA and RSA.

  2. Enter 4096 for the keysize.

  3. Press Enter to select that the key doesn’t expire.

  4. Verify that your selections are correct.

  5. Enter your GitHub username as Real Name.

  6. Enter your Github email address.

  7. Press Enter to leave the comment blank.

  8. Enter O to continue if you don’t want to make any changes.

  9. Enter a secure passphrase for your private key. (You can leave it blank if you don’t want to type in your passphrase everytime you want to commit)

  10. Get the generated key.

$ gpg --list-keys
  1. From the list of GPG keys, copy the GPG key ID you’d like to use. In this example, the GPG key ID is EXXXXX95E8DEA8E4DC96F794E4FFBC00C2CXXXXX
$ gpg --list-keys        
gpg: checking the trustdb
gpg: marginals needed: 3  completes needed: 1  trust model: pgp
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 2u
/Users/aqhmal/.gnupg/pubring.kbx
--------------------------------
pub   rsa4096 2021-02-14 [SC]
      EXXXXX95E8DEA8E4DC96F794E4FFBC00C2CXXXXX
uid           [ultimate] aqhmal <[email protected]>
sub   rsa4096 2021-02-14 [E]
  1. Set your GPG signing key in Git.
$ git config --global user.signingkey <KEY_ID>
  1. Set the GPG program in Git.
$ git config --global gpg.program /usr/local/bin/gpg
  1. Set the gpgsign during commit to true in Git.
$ git config --global commit.gpgsign true
  1. Set the GPG_TTY variable in .zshrc
$ echo 'export GPG_TTY=$(tty)' >> ~/.zshrc
$ source ~/.zshrc
  1. Export the GPG key and copy the key, beginning with -----BEGIN PGP PUBLIC KEY BLOCK----- and ending with -----END PGP PUBLIC KEY BLOCK-----.
$ gpg --armor --export <KEY_ID>
  1. Go to this page and paste the copied key.

References

Leave a Reply