Signing Git Commits
Contents
This post is a guide to sign Git commits.
macOS
Install
gnupg
andpinentry-mac
.1
brew install gnupg pinentry-mac
Generate a GPG key. You can also refer to the GitHub Docuemnt.
1
gpg --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.
1
gpg --list-secret-keys --keyid-format=long
Export the GPG key.
1
gpg --armor --export <some GPG key ID>
Add the GPG key to GitHub. You can refer to the GitHub Docuemnt.
Set
gpg-agent
up.1 2
echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf killall gpg-agent
Add Git configurations.
1 2
git config --global gpg.program gpg git config --global commit.gpgsign true
Check whether a commit was signed.
1
git log --show-signature -1
Ubuntu Server (22.04)
Install
gnupg
.1
sudo apt install gpg
Follow the above steps (described for macOS) from
2
to5
.Set the environment variable.
1
export GPG_TTY="$(tty)"
Add Git configurations.
1 2
git config --global gpg.program gpg git config --global commit.gpgsign true
Check whether a commit was signed.
1
git log --show-signature -1
Author Adonis Ling
LastMod 2023-06-27 (b1af7fc)