Skip to main content
GitHub Docs
  • All products
  • Authentication
    • Account security
      • Authentication to GitHub
      • Create a strong password
      • Update access credentials
      • Create a PAT
      • Reviewing your SSH keys
      • Deploy keys
      • Authorizing OAuth Apps
      • Authorizing GitHub Apps
      • Authorized integrations
      • Third-party applications
      • Review OAuth apps
      • Token expiration
      • Security log
      • Remove sensitive data
      • About anonymized URLs
      • GitHub's IP addresses
      • SSH key fingerprints
      • Sudo mode
      • Unauthorized access
    • Secure your account with 2FA
      • About 2FA
      • Configure 2FA
      • Configure 2FA recovery
      • Access GitHub with 2FA
      • Recover an account with 2FA
      • Change 2FA delivery method
      • Countries supporting SMS
      • Disable 2FA
    • Connect with SSH
      • About SSH
      • Check for existing SSH key
      • Generate new SSH key
      • Add a new SSH key
      • Test your SSH connection
      • SSH key passphrases
    • Troubleshooting SSH
      • Use SSH over HTTPS port
      • Recover SSH key passphrase
      • Deleted or missing SSH keys
      • Permission denied (publickey)
      • Error: Bad file number
      • Error: Key already in use
      • Permission denied other-user
      • Permission denied other-repo
      • Agent failure to sign
      • ssh-add: illegal option -- K
      • SSL certificate problem
      • Error: Unknown key type
      • SSH key audit
    • Verify commit signatures
      • Commit signature verification
      • Displaying verification for all commits
      • Existing GPG keys
      • Generating a new GPG key
      • Add a GPG key
      • Tell Git your signing key
      • Associate email with GPG key
      • Signing commits
      • Signing tags
    • Troubleshoot verification
      • Check verification status
      • Use verified email in GPG key
  • Authentication/
  • Verify commit signatures/
  • Tell Git your signing key
 
GitHub Docs
  • Authentication/
  • Verify commit signatures/
  • Tell Git your signing key
Authentication
    • Get started
    • Account and profile
    • Authentication
    • Repositories
    • Enterprise administrators
    • Billing and payments
    • Site policy
    • Organizations
    • Code security
    • Pull requests
    • GitHub Issues
    • GitHub Actions
    • GitHub Copilot
    • GitHub Codespaces
    • GitHub Packages
    • Search on GitHub
    • Developers
    • REST API
    • GraphQL API
    • GitHub CLI
    • GitHub Discussions
    • GitHub Sponsors
    • Building communities
    • GitHub Pages
    • Education
    • GitHub Desktop
    • GitHub Support
    • Atom
    • Electron
    • CodeQL
    • npm
Free, Pro, & Team
    • Free, Pro, & Team
    • Enterprise Cloud
    • Enterprise Server 3.6
    • Enterprise Server 3.5
    • Enterprise Server 3.4
    • Enterprise Server 3.3
    • Enterprise Server 3.2
    • GitHub AE
    • All Enterprise Server releases
    • About versions

 

Telling Git about your signing key

In this article

  • Telling Git about your GPG key
  • Telling Git about your GPG key
  • Telling Git about your GPG key
  • Further reading

To sign commits locally, you need to inform Git that there's a GPG or X.509 key you'd like to use.

MacWindowsLinux

Telling Git about your GPG key

If you're using a GPG key that matches your committer identity and your verified email address associated with your account on GitHub.com, then you can begin signing commits and signing tags.

If you don't have a GPG key that matches your committer identity, you need to associate an email with an existing key. For more information, see "Associating an email with your GPG key".

If you have multiple GPG keys, you need to tell Git which one to use.

  1. Open TerminalTerminalGit Bash.

  2. Use the gpg --list-secret-keys --keyid-format=long command to list the long form of the GPG keys for which you have both a public and private key. A private key is required for signing commits or tags.

    $ gpg --list-secret-keys --keyid-format=long

    Note: Some GPG installations on Linux may require you to use gpg2 --list-keys --keyid-format LONG to view a list of your existing keys instead. In this case you will also need to configure Git to use gpg2 by running git config --global gpg.program gpg2.

  3. From the list of GPG keys, copy the long form of the GPG key ID you'd like to use. In this example, the GPG key ID is 3AA5C34371567BD2:

    $ gpg --list-secret-keys --keyid-format=long
    /Users/hubot/.gnupg/secring.gpg
    ------------------------------------
    sec   4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]
    uid                          Hubot 
    ssb   4096R/42B317FD4BA89E7A 2016-03-10
  4. To set your GPG signing key in Git, paste the text below, substituting in the GPG key ID you'd like to use. In this example, the GPG key ID is 3AA5C34371567BD2:

    $ git config --global user.signingkey 3AA5C34371567BD2
  5. If you aren't using the GPG suite, run the following command in the zsh shell to add the GPG key to your .zshrc file, if it exists, or your .zprofile file:

    $ if [ -r ~/.zshrc ]; then echo 'export GPG_TTY=$(tty)' >> ~/.zshrc; \
      else echo 'export GPG_TTY=$(tty)' >> ~/.zprofile; fi

    Alternatively, if you use the bash shell, run this command:

    $ if [ -r ~/.bash_profile ]; then echo 'export GPG_TTY=$(tty)' >> ~/.bash_profile; \
      else echo 'export GPG_TTY=$(tty)' >> ~/.profile; fi
  6. Optionally, to prompt you to enter a PIN or passphrase when required, install pinentry-mac. For example, using Homebrew:

    $ brew install pinentry-mac
    $ echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
    $ killall gpg-agent

Telling Git about your X.509 key

You can use smimesign to sign commits and tags using S/MIME instead of GPG.

Note: S/MIME signature verification is available in Git 2.19 or later. To update your version of Git, see the Git website.

  1. Install smimesign.
  2. Open TerminalTerminalGit Bash.
  3. Configure Git to use S/MIME to sign commits and tags. In Git 2.19 or later, use the git config gpg.x509.program and git config gpg.format commands:
  • To use S/MIME to sign for all repositories:
    $ git config --global gpg.x509.program smimesign
    $ git config --global gpg.format x509
  • To use S/MIME to sign for a single repository:
    $ cd /path/to/my/repository
    $ git config --local gpg.x509.program smimesign
    $ git config --local gpg.format x509
    In Git 2.18 or earlier, use the git config gpg.program command:
  • To use S/MIME to sign for all repositories:
    $ git config --global gpg.program smimesign
  • To use S/MIME to sign for a single repository:
    $ cd /path/to/my/repository
    $ git config --local gpg.program smimesign
    If you're using an X.509 key that matches your committer identity, you can begin signing commits and tags.
  1. If you're not using an X.509 key that matches your committer identity, list X.509 keys for which you have both a certificate and private key using the smimesign --list-keys command.
    $ smimesign --list-keys
  2. From the list of X.509 keys, copy the certificate ID of the X.509 key you'd like to use. In this example, the certificate ID is 0ff455a2708394633e4bb2f88002e3cd80cbd76f:
    $ smimesign --list-keys
                 ID: 0ff455a2708394633e4bb2f88002e3cd80cbd76f
                S/N: a2dfa7e8c9c4d1616f1009c988bb70f
          Algorithm: SHA256-RSA
           Validity: 2017-11-22 00:00:00 +0000 UTC - 2020-11-22 12:00:00 +0000 UTC
             Issuer: CN=DigiCert SHA2 Assured ID CA,OU=www.digicert.com,O=DigiCert Inc,C=US
            Subject: CN=Octocat,O=GitHub\, Inc.,L=San Francisco,ST=California,C=US
             Emails: octocat@github.com
  3. To set your X.509 signing key in Git, paste the text below, substituting in the certificate ID you copied earlier.
  • To use your X.509 key to sign for all repositories:
    $ git config --global user.signingkey 0ff455a2708394633e4bb2f88002e3cd80cbd76f
  • To use your X.509 key to sign for a single repository:
    $ cd /path/to/my/repository
    $ git config --local user.signingkey 0ff455a2708394633e4bb2f88002e3cd80cbd76f

Telling Git about your GPG key

If you're using a GPG key that matches your committer identity and your verified email address associated with your account on GitHub.com, then you can begin signing commits and signing tags.

If you don't have a GPG key that matches your committer identity, you need to associate an email with an existing key. For more information, see "Associating an email with your GPG key".

If you have multiple GPG keys, you need to tell Git which one to use.

  1. Open TerminalTerminalGit Bash.

  2. Use the gpg --list-secret-keys --keyid-format=long command to list the long form of the GPG keys for which you have both a public and private key. A private key is required for signing commits or tags.

    $ gpg --list-secret-keys --keyid-format=long

    Note: Some GPG installations on Linux may require you to use gpg2 --list-keys --keyid-format LONG to view a list of your existing keys instead. In this case you will also need to configure Git to use gpg2 by running git config --global gpg.program gpg2.

  3. From the list of GPG keys, copy the long form of the GPG key ID you'd like to use. In this example, the GPG key ID is 3AA5C34371567BD2:

    $ gpg --list-secret-keys --keyid-format=long
    /Users/hubot/.gnupg/secring.gpg
    ------------------------------------
    sec   4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]
    uid                          Hubot 
    ssb   4096R/42B317FD4BA89E7A 2016-03-10
  4. To set your GPG signing key in Git, paste the text below, substituting in the GPG key ID you'd like to use. In this example, the GPG key ID is 3AA5C34371567BD2:

    $ git config --global user.signingkey 3AA5C34371567BD2

Telling Git about your X.509 key

You can use smimesign to sign commits and tags using S/MIME instead of GPG.

Note: S/MIME signature verification is available in Git 2.19 or later. To update your version of Git, see the Git website.

  1. Install smimesign.
  2. Open TerminalTerminalGit Bash.
  3. Configure Git to use S/MIME to sign commits and tags. In Git 2.19 or later, use the git config gpg.x509.program and git config gpg.format commands:
  • To use S/MIME to sign for all repositories:
    $ git config --global gpg.x509.program smimesign
    $ git config --global gpg.format x509
  • To use S/MIME to sign for a single repository:
    $ cd /path/to/my/repository
    $ git config --local gpg.x509.program smimesign
    $ git config --local gpg.format x509
    In Git 2.18 or earlier, use the git config gpg.program command:
  • To use S/MIME to sign for all repositories:
    $ git config --global gpg.program smimesign
  • To use S/MIME to sign for a single repository:
    $ cd /path/to/my/repository
    $ git config --local gpg.program smimesign
    If you're using an X.509 key that matches your committer identity, you can begin signing commits and tags.
  1. If you're not using an X.509 key that matches your committer identity, list X.509 keys for which you have both a certificate and private key using the smimesign --list-keys command.
    $ smimesign --list-keys
  2. From the list of X.509 keys, copy the certificate ID of the X.509 key you'd like to use. In this example, the certificate ID is 0ff455a2708394633e4bb2f88002e3cd80cbd76f:
    $ smimesign --list-keys
                 ID: 0ff455a2708394633e4bb2f88002e3cd80cbd76f
                S/N: a2dfa7e8c9c4d1616f1009c988bb70f
          Algorithm: SHA256-RSA
           Validity: 2017-11-22 00:00:00 +0000 UTC - 2020-11-22 12:00:00 +0000 UTC
             Issuer: CN=DigiCert SHA2 Assured ID CA,OU=www.digicert.com,O=DigiCert Inc,C=US
            Subject: CN=Octocat,O=GitHub\, Inc.,L=San Francisco,ST=California,C=US
             Emails: octocat@github.com
  3. To set your X.509 signing key in Git, paste the text below, substituting in the certificate ID you copied earlier.
  • To use your X.509 key to sign for all repositories:
    $ git config --global user.signingkey 0ff455a2708394633e4bb2f88002e3cd80cbd76f
  • To use your X.509 key to sign for a single repository:
    $ cd /path/to/my/repository
    $ git config --local user.signingkey 0ff455a2708394633e4bb2f88002e3cd80cbd76f

Telling Git about your GPG key

If you're using a GPG key that matches your committer identity and your verified email address associated with your account on GitHub.com, then you can begin signing commits and signing tags.

If you don't have a GPG key that matches your committer identity, you need to associate an email with an existing key. For more information, see "Associating an email with your GPG key".

If you have multiple GPG keys, you need to tell Git which one to use.

  1. Open TerminalTerminalGit Bash.

  2. Use the gpg --list-secret-keys --keyid-format=long command to list the long form of the GPG keys for which you have both a public and private key. A private key is required for signing commits or tags.

    $ gpg --list-secret-keys --keyid-format=long

    Note: Some GPG installations on Linux may require you to use gpg2 --list-keys --keyid-format LONG to view a list of your existing keys instead. In this case you will also need to configure Git to use gpg2 by running git config --global gpg.program gpg2.

  3. From the list of GPG keys, copy the long form of the GPG key ID you'd like to use. In this example, the GPG key ID is 3AA5C34371567BD2:

    $ gpg --list-secret-keys --keyid-format=long
    /Users/hubot/.gnupg/secring.gpg
    ------------------------------------
    sec   4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]
    uid                          Hubot 
    ssb   4096R/42B317FD4BA89E7A 2016-03-10
  4. To set your GPG signing key in Git, paste the text below, substituting in the GPG key ID you'd like to use. In this example, the GPG key ID is 3AA5C34371567BD2:

    $ git config --global user.signingkey 3AA5C34371567BD2
  5. To add your GPG key to your .bashrc startup file, run the following command:

    $ [ -f ~/.bashrc ] && echo 'export GPG_TTY=$(tty)' >> ~/.bashrc
    

Further reading

  • "Checking for existing GPG keys"
  • "Generating a new GPG key"
  • "Using a verified email address in your GPG key"
  • "Adding a GPG key to your GitHub account"
  • "Associating an email with your GPG key"
  • "Signing commits"
  • "Signing tags"

Did this doc help you?

Privacy policy

Help us make these docs great!

All GitHub docs are open source. See something that's wrong or unclear? Submit a pull request.

Make a contribution

Or, learn how to contribute.

Still need help?

Ask the GitHub community
Contact support
  • © 2022 GitHub, Inc.
  • Terms
  • Privacy
  • Security
  • Status
  • Help
  • Contact GitHub
  • Pricing
  • Developer API
  • Training
  • Blog
  • About