{"meta":{"title":"Telling Git about your signing key","intro":"To sign commits locally, you need to inform Git that there's a GPG, SSH, or X.509 key you'd like to use.","product":"Authentication","breadcrumbs":[{"href":"/en/authentication","title":"Authentication"},{"href":"/en/authentication/managing-commit-signature-verification","title":"Verify commit signatures"},{"href":"/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key","title":"Tell Git about your signing key"}],"documentType":"article"},"body":"# Telling Git about your signing key\n\nTo sign commits locally, you need to inform Git that there's a GPG, SSH, or X.509 key you'd like to use.\n\n## Telling Git about your GPG key\n\n<div class=\"ghd-tool mac\">\n\nIf 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.\n\n> \\[!NOTE]\n> 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](/en/authentication/managing-commit-signature-verification/associating-an-email-with-your-gpg-key).\n\nIf you have multiple GPG keys, you need to tell Git which one to use.\n\n1. Open <span class=\"platform-mac\">Terminal</span><span class=\"platform-linux\">Terminal</span><span class=\"platform-windows\">Git Bash</span>.\n\n2. If you have previously configured Git to use a different key format when signing with `--gpg-sign`, unset this configuration so the default format of `openpgp` will be used.\n\n   ```shell\n   git config --global --unset gpg.format\n   ```\n\n3. 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.\n\n   ```shell copy\n   gpg --list-secret-keys --keyid-format=long\n   ```\n\n   > \\[!NOTE]\n   > 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`.\n\n4. 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`:\n\n   ```shell copy\n   $ gpg --list-secret-keys --keyid-format=long\n   /Users/hubot/.gnupg/secring.gpg\n   ------------------------------------\n   sec   4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]\n   uid                          Hubot <hubot@example.com>\n   ssb   4096R/4BB6D45482678BE3 2016-03-10\n   ```\n\n5. To set your primary GPG signing key in Git, paste the text below, substituting in the GPG primary key ID you'd like to use. In this example, the GPG key ID is `3AA5C34371567BD2`:\n\n   ```shell\n   git config --global user.signingkey 3AA5C34371567BD2\n   ```\n\n   Alternatively, you may want to use a subkey. In this example, the GPG subkey ID is `4BB6D45482678BE3`:\n\n   ```shell\n   git config --global user.signingkey 4BB6D45482678BE3\n   ```\n\n   If you use multiple keys and subkeys, then you should append an exclamation mark `!` to the key to tell git that this is your preferred key. Sometimes you may need to escape the exclamation mark with a back slash: `\\!`.\n\n6. Optionally, to configure Git to sign all commits and tags by default, enter the following command:\n\n   ```shell\n   git config --global commit.gpgsign true\n   git config --global tag.gpgSign true\n   ```\n\n   For more information, see [Signing commits](/en/authentication/managing-commit-signature-verification/signing-commits).\n\n7. 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:\n\n   ```shell\n   $ if [ -r ~/.zshrc ]; then echo -e '\\nexport GPG_TTY=$(tty)' >> ~/.zshrc; \\\n     else echo -e '\\nexport GPG_TTY=$(tty)' >> ~/.zprofile; fi\n   ```\n\n   Alternatively, if you use the `bash` shell, run this command:\n\n   ```shell\n   $ if [ -r ~/.bash_profile ]; then echo -e '\\nexport GPG_TTY=$(tty)' >> ~/.bash_profile; \\\n     else echo -e '\\nexport GPG_TTY=$(tty)' >> ~/.profile; fi\n   ```\n\n8. Optionally, to prompt you to enter a PIN or passphrase when required, install `pinentry-mac`. For example, using [Homebrew](https://brew.sh/):\n\n   ```shell\n   brew install pinentry-mac\n   echo \"pinentry-program $(which pinentry-mac)\" >> ~/.gnupg/gpg-agent.conf\n   killall gpg-agent\n   ```\n\n</div>\n\n<div class=\"ghd-tool windows\">\n\nIf 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.\n\n> \\[!NOTE]\n> 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](/en/authentication/managing-commit-signature-verification/associating-an-email-with-your-gpg-key).\n\nIf you have multiple GPG keys, you need to tell Git which one to use.\n\n1. Open <span class=\"platform-mac\">Terminal</span><span class=\"platform-linux\">Terminal</span><span class=\"platform-windows\">Git Bash</span>.\n2. If you have previously configured Git to use a different key format when signing with `--gpg-sign`, unset this configuration so the default format of `openpgp` will be used.\n\n   ```shell\n   git config --global --unset gpg.format\n   ```\n3. 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.\n\n   ```shell copy\n   gpg --list-secret-keys --keyid-format=long\n   ```\n\n   > \\[!NOTE]\n   > 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`.\n4. 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`:\n\n   ```shell copy\n   $ gpg --list-secret-keys --keyid-format=long\n   /Users/hubot/.gnupg/secring.gpg\n   ------------------------------------\n   sec   4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]\n   uid                          Hubot <hubot@example.com>\n   ssb   4096R/4BB6D45482678BE3 2016-03-10\n   ```\n5. To set your primary GPG signing key in Git, paste the text below, substituting in the GPG primary key ID you'd like to use. In this example, the GPG key ID is `3AA5C34371567BD2`:\n\n   ```shell\n   git config --global user.signingkey 3AA5C34371567BD2\n   ```\n\n   Alternatively, you may want to use a subkey. In this example, the GPG subkey ID is `4BB6D45482678BE3`:\n\n   ```shell\n   git config --global user.signingkey 4BB6D45482678BE3\n   ```\n\n   If you use multiple keys and subkeys, then you should append an exclamation mark `!` to the key to tell git that this is your preferred key. Sometimes you may need to escape the exclamation mark with a back slash: `\\!`.\n6. Optionally, to configure Git to sign all commits and tags by default, enter the following command:\n\n   ```shell\n   git config --global commit.gpgsign true\n   git config --global tag.gpgSign true\n   ```\n\n   For more information, see [Signing commits](/en/authentication/managing-commit-signature-verification/signing-commits).\n\n</div>\n\n<div class=\"ghd-tool linux\">\n\nIf 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.\n\n> \\[!NOTE]\n> 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](/en/authentication/managing-commit-signature-verification/associating-an-email-with-your-gpg-key).\n\nIf you have multiple GPG keys, you need to tell Git which one to use.\n\n1. Open <span class=\"platform-mac\">Terminal</span><span class=\"platform-linux\">Terminal</span><span class=\"platform-windows\">Git Bash</span>.\n2. If you have previously configured Git to use a different key format when signing with `--gpg-sign`, unset this configuration so the default format of `openpgp` will be used.\n\n   ```shell\n   git config --global --unset gpg.format\n   ```\n3. 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.\n\n   ```shell copy\n   gpg --list-secret-keys --keyid-format=long\n   ```\n\n   > \\[!NOTE]\n   > 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`.\n4. 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`:\n\n   ```shell copy\n   $ gpg --list-secret-keys --keyid-format=long\n   /Users/hubot/.gnupg/secring.gpg\n   ------------------------------------\n   sec   4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]\n   uid                          Hubot <hubot@example.com>\n   ssb   4096R/4BB6D45482678BE3 2016-03-10\n   ```\n5. To set your primary GPG signing key in Git, paste the text below, substituting in the GPG primary key ID you'd like to use. In this example, the GPG key ID is `3AA5C34371567BD2`:\n\n   ```shell\n   git config --global user.signingkey 3AA5C34371567BD2\n   ```\n\n   Alternatively, you may want to use a subkey. In this example, the GPG subkey ID is `4BB6D45482678BE3`:\n\n   ```shell\n   git config --global user.signingkey 4BB6D45482678BE3\n   ```\n\n   If you use multiple keys and subkeys, then you should append an exclamation mark `!` to the key to tell git that this is your preferred key. Sometimes you may need to escape the exclamation mark with a back slash: `\\!`.\n6. Optionally, to configure Git to sign all commits and tags by default, enter the following command:\n\n   ```shell\n   git config --global commit.gpgsign true\n   git config --global tag.gpgSign true\n   ```\n\n   For more information, see [Signing commits](/en/authentication/managing-commit-signature-verification/signing-commits).\n7. To add your GPG key to your `.bashrc` startup file, run the following command:\n\n   ```bash\n   [ -f ~/.bashrc ] && echo -e '\\nexport GPG_TTY=$(tty)' >> ~/.bashrc\n   ```\n\n</div>\n\n## Telling Git about your SSH key\n\nYou can use an existing SSH key to sign commits and tags, or generate a new one specifically for signing. For more information, see [Generating a new SSH key and adding it to the ssh-agent](/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent).\n\n> \\[!NOTE]\n> SSH signature verification is available in Git 2.34 or later. To update your version of Git, see the [Git](https://git-scm.com/downloads) website.\n\n1. Open <span class=\"platform-mac\">Terminal</span><span class=\"platform-linux\">Terminal</span><span class=\"platform-windows\">Git Bash</span>.\n2. Configure Git to use SSH to sign commits and tags:\n\n   ```bash\n   git config --global gpg.format ssh\n   ```\n3. To set your SSH signing key in Git, paste the text below, substituting **/PATH/TO/.SSH/KEY.PUB** with the path to the public key you'd like to use.\n\n   ```bash\n   git config --global user.signingkey /PATH/TO/.SSH/KEY.PUB\n   ```\n\n<div class=\"ghd-tool windows\">\n\n## Telling Git about your X.509 key\n\nYou can use [smimesign](https://github.com/github/smimesign) to sign commits and tags using S/MIME.\n\n> \\[!NOTE]\n> S/MIME signature verification is available in Git 2.19 or later. To update your version of Git, see the [Git](https://git-scm.com/downloads) website.\n\n1. Install [smimesign](https://github.com/github/smimesign#installation).\n\n2. Open <span class=\"platform-mac\">Terminal</span><span class=\"platform-linux\">Terminal</span><span class=\"platform-windows\">Git Bash</span>.\n\n3. 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:\n   * To use S/MIME to sign for all repositories:\n\n     ```shell\n     git config --global gpg.x509.program smimesign\n     git config --global gpg.format x509\n     ```\n\n   * To use S/MIME to sign for a single repository:\n\n     ```shell\n     cd PATH-TO-REPOSITORY\n     git config --local gpg.x509.program smimesign\n     git config --local gpg.format x509\n     ```\n\n     In Git 2.18 or earlier, use the `git config gpg.program` command:\n\n   * To use S/MIME to sign for all repositories:\n\n     ```shell\n     git config --global gpg.program smimesign\n     ```\n\n   * To use S/MIME to sign for a single repository:\n\n     ```shell\n     cd  PATH-TO-REPOSITORY\n     git config --local gpg.program smimesign\n     ```\n\n     If you're using an X.509 key that matches your committer identity, you can begin signing commits and tags.\n\n4. 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.\n\n   ```shell\n   smimesign --list-keys\n   ```\n\n5. 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`:\n\n   ```shell\n   $ smimesign --list-keys\n                ID: 0ff455a2708394633e4bb2f88002e3cd80cbd76f\n               S/N: a2dfa7e8c9c4d1616f1009c988bb70f\n         Algorithm: SHA256-RSA\n          Validity: 2017-11-22 00:00:00 +0000 UTC - 2020-11-22 12:00:00 +0000 UTC\n            Issuer: CN=DigiCert SHA2 Assured ID CA,OU=www.digicert.com,O=DigiCert Inc,C=US\n           Subject: CN=Octocat,O=GitHub\\, Inc.,L=San Francisco,ST=California,C=US\n            Emails: octocat@github.com\n   ```\n\n6. To set your X.509 signing key in Git, paste the text below, substituting in the certificate ID you copied earlier.\n   * To use your X.509 key to sign for all repositories:\n\n     ```shell\n     git config --global user.signingkey 0ff455a2708394633e4bb2f88002e3cd80cbd76f\n     ```\n\n   * To use your X.509 key to sign for a single repository:\n\n     ```shell\n     cd  PATH-TO-REPOSITORY\n     git config --local user.signingkey 0ff455a2708394633e4bb2f88002e3cd80cbd76f\n     ```\n\n</div>\n\n<div class=\"ghd-tool mac\">\n\n## Telling Git about your X.509 key\n\nYou can use [smimesign](https://github.com/github/smimesign) to sign commits and tags using S/MIME.\n\n> \\[!NOTE]\n> S/MIME signature verification is available in Git 2.19 or later. To update your version of Git, see the [Git](https://git-scm.com/downloads) website.\n\n1. Install [smimesign](https://github.com/github/smimesign#installation).\n\n2. Open <span class=\"platform-mac\">Terminal</span><span class=\"platform-linux\">Terminal</span><span class=\"platform-windows\">Git Bash</span>.\n\n3. 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:\n   * To use S/MIME to sign for all repositories:\n\n     ```shell\n     git config --global gpg.x509.program smimesign\n     git config --global gpg.format x509\n     ```\n\n   * To use S/MIME to sign for a single repository:\n\n     ```shell\n     cd PATH-TO-REPOSITORY\n     git config --local gpg.x509.program smimesign\n     git config --local gpg.format x509\n     ```\n\n     In Git 2.18 or earlier, use the `git config gpg.program` command:\n\n   * To use S/MIME to sign for all repositories:\n\n     ```shell\n     git config --global gpg.program smimesign\n     ```\n\n   * To use S/MIME to sign for a single repository:\n\n     ```shell\n     cd  PATH-TO-REPOSITORY\n     git config --local gpg.program smimesign\n     ```\n\n     If you're using an X.509 key that matches your committer identity, you can begin signing commits and tags.\n\n4. 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.\n\n   ```shell\n   smimesign --list-keys\n   ```\n\n5. 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`:\n\n   ```shell\n   $ smimesign --list-keys\n                ID: 0ff455a2708394633e4bb2f88002e3cd80cbd76f\n               S/N: a2dfa7e8c9c4d1616f1009c988bb70f\n         Algorithm: SHA256-RSA\n          Validity: 2017-11-22 00:00:00 +0000 UTC - 2020-11-22 12:00:00 +0000 UTC\n            Issuer: CN=DigiCert SHA2 Assured ID CA,OU=www.digicert.com,O=DigiCert Inc,C=US\n           Subject: CN=Octocat,O=GitHub\\, Inc.,L=San Francisco,ST=California,C=US\n            Emails: octocat@github.com\n   ```\n\n6. To set your X.509 signing key in Git, paste the text below, substituting in the certificate ID you copied earlier.\n   * To use your X.509 key to sign for all repositories:\n\n     ```shell\n     git config --global user.signingkey 0ff455a2708394633e4bb2f88002e3cd80cbd76f\n     ```\n\n   * To use your X.509 key to sign for a single repository:\n\n     ```shell\n     cd  PATH-TO-REPOSITORY\n     git config --local user.signingkey 0ff455a2708394633e4bb2f88002e3cd80cbd76f\n     ```\n\n</div>\n\n## Further reading\n\n* [Adding a new SSH key to your GitHub account](/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account).\n* [Signing commits](/en/authentication/managing-commit-signature-verification/signing-commits)\n* [Signing tags](/en/authentication/managing-commit-signature-verification/signing-tags)"}