Skip to content

Sign your GitHub commits with a code signing certificate and a YubiKey

Updated in 2026. The ykman commands now use the YubiKey Manager 4 syntax, and the slot numbers are consistent throughout. GitHub can now also verify commits signed with SSH keys, which is simpler if you do not need a certificate from a certificate authority.

I used to sign my commits with a GPG key, based on Geoffrey Huntley's excellent notes on Git (archived copy).

This article uses an X.509 certificate stored on a YubiKey instead.

The guide only works with YubiKey devices that support PIV (smart card mode). You may be able to adapt it to other PIV security devices.

You need a code signing certificate from a trusted certificate authority. GitHub checks S/MIME certificates against the Debian CA certificates package, which uses the same list as Mozilla's browsers. I found DigiCert very good. They provided notary services over Skype for free, which helped because notary services are expensive in Australia.

The instructions are for Windows, but you can adapt them for other platforms.

Why do this?

Why sign your Git commits?

  • People know the commit came from someone with access to your private key, which ideally means you.
  • GitHub marks the commit as verified, which builds trust. With a certificate from a certificate authority, GitHub also shows who issued it.
  • The certificate authority checked your identity documents before issuing the certificate.

Why use a YubiKey?

  • Your private key is stored on the YubiKey and never leaves it. You unlock it with a PIN, once per session.
  • You can also require a touch of the YubiKey's button for every signature.
  • The same YubiKey can be your second factor for signing in to GitHub.

Set up the YubiKey

First, get an X.509 code signing certificate from a trusted provider such as DigiCert. Make sure the certificate request contains the email address you use on GitHub. Follow the provider's instructions to install it.

On Windows you can use the YubiKey Minidriver, but I found the YubiKey Manager command line (ykman) easier.

These steps use a PIN policy of once per session and no touch policy. The ykman PIV documentation lists the other options. They install the key into slot 9c, the digital signature slot.

  1. Export the certificate and its private key as a PFX file. Back it up somewhere safe: anyone who gets this file can pretend to be you.
  2. Install YubiKey Manager and open a command prompt.
  3. Change the PIN from the default of 123456, if you have not already: ykman piv access change-pin -P 123456 -n <new pin>
  4. Import the private key: ykman piv keys import --pin-policy ONCE 9c C:\path\to\your.pfx
  5. When prompted, enter the PIN, the management key and the PFX password.
  6. Import the certificate: ykman piv certificates import 9c C:\path\to\your.pfx
  7. When prompted, enter the PIN, the management key and the PFX password again.
  8. If the certificate does not show up in smimesign in the next section, sign out of Windows and back in.

Set up Git

These steps use S/MIME signing for all your repositories. GitHub's guide to signing keys covers the other options.

We wrap smimesign in a batch file so it always asks a timestamp authority to timestamp the signature. When I wrote this, smimesign had an open issue with timestamp authorities.

  1. Install smimesign.

  2. Create a batch file called sign.cmd in a folder on your PATH:

    @echo off
    smimesign.exe --timestamp-authority http://timestamp.digicert.com %*
    
  3. Tell Git to use it:

    git config --global gpg.x509.program c:/path/to/sign.cmd
    git config --global gpg.format x509
    git config --global commit.gpgsign true
    
  4. Run smimesign --list-keys and copy the serial number of the certificate you want to use. Use the serial number, not the ID.

  5. Set it as your signing key: git config --global user.signingkey a2dfa7e8c9c4d1616f1009c988bb70f

Each time you commit, Windows now asks for the PIN you set earlier.

Thanks