Skip to content

Commit 64d6b81

Browse files
authored
Revise GPG signing guide for macOS & Windows
Updated instructions for GPG key generation and configuration on macOS and Windows. Also updated GitHub Actions checkout action version.
1 parent b5bf70a commit 64d6b81

File tree

1 file changed

+108
-55
lines changed

1 file changed

+108
-55
lines changed

practices/guides/commit-signing.md

Lines changed: 108 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -13,76 +13,129 @@
1313

1414
### macOS
1515

16-
- Install the [Brew package manager](https://brew.sh)
16+
1. Install `gnupg` & `pinentry-mac` with [Brew](https://brew.sh):
1717

18-
```bash
19-
brew upgrade
20-
brew install gnupg pinentry-mac
21-
gpg --full-generate-key
22-
```
18+
```bash
19+
brew upgrade
20+
brew install gnupg pinentry-mac
21+
sed -i '' '/^export GPG_TTY/d' ~/.zshrc
22+
echo export GPG_TTY=\$\(tty\) >> ~/.zshrc
23+
source ~/.zshrc
24+
PINENTRY_BIN=$(whereis -q pinentry-mac)
25+
touch ~/.gnupg/gpg-agent.conf
26+
sed -i '' '/^pinentry-program/d' ~/.gnupg/gpg-agent.conf
27+
echo "pinentry-program ${PINENTRY_BIN}" >> ~/.gnupg/gpg-agent.conf
28+
gpgconf --kill gpg-agent
29+
```
2330

24-
- Accept the defaults, Curve 25519 etc.
25-
- Enter your GitHub account name as the Real Name
26-
- Enter your GitHub account email as the Email Address
27-
- Avoid adding a comment (this *may* prevent git from auto-selecting a key - see Troubleshooting section below)
28-
- You can use the privacy *@users.noreply.github.com* email address listed in the GitHub profile: *Settings > Email*
29-
- Define a passphrase for the key and keep it in your password manager
31+
1. Create a new GPG key:
3032

31-
```bash
32-
gpg --armor --export ${my_email_address} | pbcopy
33-
```
33+
```bash
34+
gpg --full-generate-key
35+
```
3436

35-
- Public key is now in your clipboard - in your GitHub account add it to your profile via *Settings > SSH and GPG Keys> Add New GPG Key*
36-
- Paste it in
37+
1. Pick `RSA and RSA`, or `RSA (sign only)` (there is no elliptic curve cryptography (ECC) support at the time of writing)
38+
1. `keysize` = `4096` bits (the minimum accepted for GitHub)
39+
1. `Real name` = Your GitHub handle
40+
1. `Email address` = Your GitHub account email [listed on your GitHub profile](https://github.com/settings/emails) (you can use the privacy *@users.noreply.github.com* email address): `Settings` -> `Emails` -> `Keep my email addresses private`)
3741

38-
```bash
39-
git config --global user.email ${my_email_address} # same one used during key generation
40-
git config --global user.name ${my_username}
41-
git config --global commit.gpgsign true
42-
sed -i '' '/^export GPG_TTY/d' ~/.zshrc
43-
echo export GPG_TTY=\$\(tty\) >> ~/.zshrc
44-
source ~/.zshrc
45-
PINENTRY_BIN=$(whereis -q pinentry-mac)
46-
sed -i '' '/^pinentry-program/d' ~/.gnupg/gpg-agent.conf
47-
echo "pinentry-program ${PINENTRY_BIN}" >> ~/.gnupg/gpg-agent.conf
48-
gpgconf --kill gpg-agent
49-
```
42+
> If you go for the private email option, consider enabling `Block command line pushes that expose my email`.
43+
1. Avoid adding a comment (this *may* prevent git from auto-selecting a key - see Troubleshooting section below)
44+
1. Define a passphrase for the key
45+
46+
1. Check the key was made successfully:
47+
48+
```bash
49+
gpg -k
50+
```
5051

51-
The first time you commit you will be prompted to add the GPG key passphrase to the macOS Keychain. Thereafter signing will happen seamlessly without prompts.
52+
1. Export the PGP PUBLIC KEY (to your clipboard):
5253

53-
Most of the published solutions for this don't work because *brew* seems to have moved the default folder for binaries, plus many guides contain obsolete settings for *gpg-agent*.
54+
```bash
55+
gpg --armor --export ${my_email_address} | pbcopy
56+
```
57+
58+
1. [Add the public key to your GitHub account](https://github.com/settings/gpg/new) (`Settings` -> `SSH and GPG keys` -> `New GPG key`)
59+
60+
> Note the `Key ID` as you'll need this in the next step.
61+
62+
1. Set your local git config to use GPG signing:
63+
64+
```bash
65+
git config --global user.email ${my_email_address} # same one used during key generation
66+
git config --global user.name ${my_username}
67+
git config --global user.signingkey = ${key_id}
68+
git config --global commit.gpgsign true
69+
git config --global tag.gpgsign true
70+
```
71+
72+
> The first time you commit you will be prompted to add the GPG key passphrase to the macOS Keychain. Thereafter signing will happen seamlessly without prompts.
73+
>
74+
> Most of the published solutions for this don't work because *brew* seems to have moved the default folder for binaries, plus many guides contain obsolete settings for *gpg-agent*.
5475

5576
### Windows
5677

57-
- Install [Git for Windows](https://git-scm.com/download/win), which includes Bash and GnuPG
58-
- Right-click on the Desktop > *Git Bash Here*
78+
1. Install [Git for Windows](https://git-scm.com/download/win) (which includes Bash and GnuPG)
79+
1. Right-click on the Desktop -> `Open Git Bash here`
80+
1. Create a new GPG key:
5981

60-
```bash
61-
gpg --full-generate-key
62-
```
82+
```bash
83+
gpg --full-generate-key
84+
```
6385

64-
- Pick *RSA and RSA*, or *RSA (sign only)* - there is no elliptic curve cryptography (ECC) support at the time of writing
65-
- Set key size to 4096 bit, the minimum accepted for GitHub
66-
- Enter your GitHub account name as the Real Name
67-
- Enter your GitHub account email as the Email Address
68-
- Avoid adding a comment (this *may* prevent git from auto-selecting a key - see Troubleshooting section below)
69-
- You can use the privacy *@users.noreply.github.com* email address listed in the GitHub profile: *Settings > Email*
70-
- Define a passphrase for the key and keep it in your password manager
86+
1. Pick `RSA and RSA`, or `RSA (sign only)` (there is no elliptic curve cryptography (ECC) support at the time of writing)
87+
1. `keysize` = `4096` bits (the minimum accepted for GitHub)
88+
1. `Real name` = Your GitHub handle
89+
1. `Email address` = Your GitHub account email [listed on your GitHub profile](https://github.com/settings/emails) (you can use the privacy *@users.noreply.github.com* email address): `Settings` -> `Emails` -> `Keep my email addresses private`)
7190

72-
```bash
73-
gpg --armor --export ${my_email_address} | clip
74-
```
91+
> If you go for the private email option, consider enabling `Block command line pushes that expose my email`.
92+
1. Avoid adding a comment (this *may* prevent git from auto-selecting a key - see Troubleshooting section below)
93+
1. Define a passphrase for the key
7594

76-
- Public key is now in your clipboard - in your GitHub account add it to your profile via *Settings > SSH and GPG Keys> Add New GPG Key*
77-
- Paste it in
95+
1. Export the PGP PUBLIC KEY (to your clipboard):
7896

79-
```bash
80-
git config --global user.email ${my_email_address} # same one used during key generation
81-
git config --global user.name ${my_username}
82-
git config --global commit.gpgsign true
83-
```
97+
```bash
98+
gpg --armor --export ${my_email_address} | clip
99+
```
100+
101+
1. [Add the public key to your GitHub account](https://github.com/settings/gpg/new) (`Settings` -> `SSH and GPG keys` -> `New GPG key`)
102+
103+
> Note the `Key ID` as you'll need this in the next step.
104+
105+
1. Set your local git config to use GPG signing:
106+
107+
```bash
108+
git config --global user.email ${my_email_address} # same one used during key generation
109+
git config --global user.name ${my_username}
110+
git config --global user.signingkey = ${key_id}
111+
git config --global commit.gpgsign true
112+
git config --global tag.gpgsign true
113+
```
114+
115+
1. Optional: Your new GPG key can be used within WSL, but not from Windows; to enable this:
116+
117+
1. Export the key:
118+
119+
```bash
120+
gpg --output <GitHub handle>.pgp --export-secret-key ${my_email_address}$
121+
```
122+
123+
1. Install [Gpg4win](https://www.gpg4win.org/) (which includes GnuPG and Kleopatra)
124+
125+
> **Ensure both `GnuPG` and `Kleopatra` are installed!**
126+
127+
1. Open Kleopatra -> `Import` -> Select the `<GitHub handle>.pgp` file created in the first step.
128+
1. In `cmd`, set your local git config to use GPG signing:
129+
130+
```bash
131+
git config --global user.email ${my_email_address} # same one used during key generation
132+
git config --global user.name ${my_username}
133+
git config --global user.signingkey = ${key_id}
134+
git config --global commit.gpgsign true
135+
git config --global tag.gpgsign true
136+
```
84137
85-
When you commit you will be prompted to enter the GPG key passphrase into a Pinentry window.
138+
> When you commit, you'll now be prompted to enter the GPG key passphrase into a Pinentry window.
86139

87140
## From Pipelines
88141

@@ -97,7 +150,7 @@ The workflow would then use a Personal Access Token, stored with the GPG private
97150
```yaml
98151
steps:
99152
- name: Checkout
100-
uses: actions/checkout@v3
153+
uses: actions/checkout@v5
101154
with:
102155
token: ${{ secrets.BOT_PAT }}
103156
ref: main

0 commit comments

Comments
 (0)