Skip to content

Commit d0c38e0

Browse files
authored
Enhance commit signing guide with SSH instructions
Expanded the commit signing guide to include SSH signing instructions and troubleshooting tips.
1 parent 504743f commit d0c38e0

File tree

1 file changed

+62
-10
lines changed

1 file changed

+62
-10
lines changed

practices/guides/commit-signing.md

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
# Git commit signing setup guide
22

3-
## From Workstations
3+
Using GPG, SSH, or S/MIME, you can sign commits and tags locally. These commits and tags are marked as verified on GitHub so other people can be confident that the changes come from a trusted source.
44

5-
### macOS
5+
The instructions on this page focus on GPG and SSH.
6+
7+
> You should only set up **one** of these options - **don't attempt to set up GPG and SSH commit signing**!
8+
9+
See the full GitHub documentation [here](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification).
10+
11+
## GPG commit signing
12+
13+
### From Workstations
14+
15+
If you have already committed and need to retrospectively sign commits, follow the instructions below, then follow the [retrospective commit signing instructions](./retrospective-commit-signing.md).
16+
17+
#### macOS
618

719
1. Install `gnupg` & `pinentry-mac` with [Brew](https://brew.sh):
820

@@ -76,7 +88,7 @@
7688
...
7789
```
7890
79-
### Windows/WSL
91+
#### Windows/WSL
8092
8193
1. Install (as administrator) [Git for Windows](https://git-scm.com/download/win) (which includes Bash and GnuPG)
8294
1. Open `Git Bash`
@@ -182,9 +194,9 @@
182194
...
183195
```
184196

185-
## From Pipelines
197+
### From Pipelines
186198

187-
### GitHub Actions
199+
#### GitHub Actions
188200

189201
A GitHub Actions workflow will by default authenticate using a [GITHUB_TOKEN](https://docs.github.com/en/actions/security-guides/automatic-token-authentication) which is generated automatically.
190202

@@ -219,7 +231,7 @@ git commit ${GITHUB_SIGNING_OPTION} -am "Automated commit from GitHub Actions: $
219231
git push
220232
```
221233

222-
### AWS CodePipeline
234+
#### AWS CodePipeline
223235

224236
The cryptographic libraries in the default Amazon Linux 2 distro are very old, and do not support elliptic curve cryptography. When using pre-existing solution elements updating the build container is not always an option. This restricts the GPG key algorithm to RSA. You should use RSA-4096, which is the required minimum for GitHub.
225237

@@ -272,10 +284,50 @@ git commit ${GITHUB_SIGNING_OPTION} -am "Automated commit from ${SCRIPT_URL}"
272284
git push
273285
```
274286

275-
## Troubleshooting
287+
### Troubleshooting
276288

277-
Re-run your git command prefixed with GIT_TRACE=1
289+
Re-run your git command prefixed with `GIT_TRACE=1`.
290+
291+
A failure to sign a commit is usually because the name or email does not quite match those which were used to generate the GPG key, so git cannot auto-select a key. Ensure that these are indeed consistent. (If you added a comment when creating your GPG key, this *may* cause a mismatch: the comment will be visible when listing your GPG keys, e.g. `RealName (Comment) <EmailAddress>`.) You are able to [force a choice of signing key](https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key), though this should not be necessary.
292+
293+
## SSH commit signing
294+
295+
1. If you do not already have SSH key access set up on your GitHub account, first [generate a new SSH key](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent). To create a new SSH key, you need to run the following command. This will generate a new SSH key of the type `ed25519` and associate it with your email address (replace `<my_email_address>` with your actual email address):
296+
297+
```shell
298+
ssh-keygen -t ed25519 -C "<my_email_address>" -f "~/.ssh/github-signing-key"
299+
```
278300

279-
A failure to sign a commit is usually because the name or email does not quite match those which were used to generate the GPG key, so git cannot auto-select a key. Ensure that these are indeed consistent. (If you added a comment when creating your gpg key, this *may* cause a mismatch: the comment will be visible when listing your gpg keys, e.g. `RealName (Comment) <EmailAddress>`.) You are able to [force a choice of signing key](https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key), though this should not be necessary.
301+
> When you run this command, it will ask you to enter a passphrase. Choose a strong passphrase and make sure to remember it, as you will need to provide it when your key is loaded by the SSH agent.
302+
303+
1. Signing commits with an SSH key is not the default method, so you need to [configure Git](https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key#telling-git-about-your-ssh-key) accordingly:
304+
305+
1. Run the following command to instruct Git to use the SSH signing key format, instead of the default GPG:
306+
307+
```shell
308+
git config --global gpg.format ssh
309+
```
310+
311+
1. Next, specify the private key for Git to use:
312+
313+
```shell
314+
git config --global user.signingkey ~/.ssh/github-signing-key
315+
```
316+
317+
1. Lastly, instruct Git to sign all of your commits:
318+
319+
```shell
320+
git config --global commit.gpgsign true
321+
```
322+
323+
1. [Add the SSH public key to your GitHub account](https://github.com/settings/ssh/new) (`Settings` -> `SSH and GPG keys` -> `New SSH key`)
324+
325+
1. `Key type` = `Signing Key`
326+
1. Copy the contents of your public key file and paste it into the `Key` field.
327+
328+
```shell
329+
cat ~/.ssh/github-signing-key.pub
330+
```
331+
1. `Add SSH key`
280332

281-
If you have already committed and need to retrospectively sign this commit [please follow the instructions here](./retrospective-commit-signing.md).
333+
1. To ensure your configuration works as expected, make a commit to a branch locally and push it to GitHub. When you view the commit history of the branch on GitHub, [your latest commit](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification#about-commit-signature-verification) should now display a `Verified` tag, which indicates successful signing with your GPG or SSH key.

0 commit comments

Comments
 (0)