Signing Git Commits
Contents
This post is a guide to sign Git commits.
macOS
Install
gnupgandpinentry-mac.1brew install gnupg pinentry-macGenerate a GPG key. You can also refer to the GitHub Docuemnt.
1gpg --full-generate-key- At the prompt, specify the kind of key you want (e.g.
RSA (sign only)). - At the prompt, specify the key size (>= 4096) you want (e.g.
4096).
- At the prompt, specify the kind of key you want (e.g.
Get the GPG key ID from the output of the following command.
1gpg --list-secret-keys --keyid-format=longExport the GPG key.
1gpg --armor --export <some GPG key ID>Add the GPG key to GitHub. You can refer to the GitHub Docuemnt.
Set
gpg-agentup.1 2echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf killall gpg-agentAdd Git configurations.
1 2git config --global gpg.program gpg git config --global commit.gpgsign trueCheck whether a commit was signed.
1git log --show-signature -1
Ubuntu Server (22.04)
Install
gnupg.1sudo apt install gpgFollow the above steps (described for macOS) from
2to5.Set the environment variable.
1export GPG_TTY="$(tty)"Add Git configurations.
1 2git config --global gpg.program gpg git config --global commit.gpgsign trueCheck whether a commit was signed.
1git log --show-signature -1
Author Adonis Ling
LastMod 2023-06-27 (b1af7fc)