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 your GitHub Enterprise Server instance, 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.
-
Open TerminalTerminalGit Bash.
-
If you have previously configured Git to use a different key format when signing with
--gpg-sign, unset this configuration so the default format ofopenpgpwill be used.git config --global --unset gpg.format -
Use the
gpg --list-secret-keys --keyid-format=longcommand 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.Shell gpg --list-secret-keys --keyid-format=long
gpg --list-secret-keys --keyid-format=longNote: Some GPG installations on Linux may require you to use
gpg2 --list-keys --keyid-format LONGto view a list of your existing keys instead. In this case you will also need to configure Git to usegpg2by runninggit config --global gpg.program gpg2. -
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:Shell $ gpg --list-secret-keys --keyid-format=long /Users/hubot/.gnupg/secring.gpg ------------------------------------ sec 4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10] uid Hubot <hubot@example.com> ssb 4096R/4BB6D45482678BE3 2016-03-10
$ gpg --list-secret-keys --keyid-format=long /Users/hubot/.gnupg/secring.gpg ------------------------------------ sec 4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10] uid Hubot <hubot@example.com> ssb 4096R/4BB6D45482678BE3 2016-03-10 -
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:git config --global user.signingkey 3AA5C34371567BD2Alternatively, when setting a subkey include the
!suffix. In this example, the GPG subkey ID is4BB6D45482678BE3:git config --global user.signingkey 4BB6D45482678BE3! -
Optionally, to configure Git to sign all commits by default, enter the following command:
git config --global commit.gpgsign trueFor more information, see "Signing commits."
-
If you aren't using the GPG suite, run the following command in the
zshshell to add the GPG key to your.zshrcfile, if it exists, or your.zprofilefile:$ if [ -r ~/.zshrc ]; then echo -e '\nexport GPG_TTY=$(tty)' >> ~/.zshrc; \ else echo -e '\nexport GPG_TTY=$(tty)' >> ~/.zprofile; fiAlternatively, if you use the
bashshell, run this command:$ if [ -r ~/.bash_profile ]; then echo -e '\nexport GPG_TTY=$(tty)' >> ~/.bash_profile; \ else echo -e '\nexport GPG_TTY=$(tty)' >> ~/.profile; fi -
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
If you're using a GPG key that matches your committer identity and your verified email address associated with your account on your GitHub Enterprise Server instance, 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.
-
Open TerminalTerminalGit Bash.
-
If you have previously configured Git to use a different key format when signing with
--gpg-sign, unset this configuration so the default format ofopenpgpwill be used.git config --global --unset gpg.format -
Use the
gpg --list-secret-keys --keyid-format=longcommand 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.Shell gpg --list-secret-keys --keyid-format=long
gpg --list-secret-keys --keyid-format=longNote: Some GPG installations on Linux may require you to use
gpg2 --list-keys --keyid-format LONGto view a list of your existing keys instead. In this case you will also need to configure Git to usegpg2by runninggit config --global gpg.program gpg2. -
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:Shell $ gpg --list-secret-keys --keyid-format=long /Users/hubot/.gnupg/secring.gpg ------------------------------------ sec 4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10] uid Hubot <hubot@example.com> ssb 4096R/4BB6D45482678BE3 2016-03-10
$ gpg --list-secret-keys --keyid-format=long /Users/hubot/.gnupg/secring.gpg ------------------------------------ sec 4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10] uid Hubot <hubot@example.com> ssb 4096R/4BB6D45482678BE3 2016-03-10 -
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:git config --global user.signingkey 3AA5C34371567BD2Alternatively, when setting a subkey include the
!suffix. In this example, the GPG subkey ID is4BB6D45482678BE3:git config --global user.signingkey 4BB6D45482678BE3! -
Optionally, to configure Git to sign all commits by default, enter the following command:
git config --global commit.gpgsign trueFor more information, see "Signing commits."
If you're using a GPG key that matches your committer identity and your verified email address associated with your account on your GitHub Enterprise Server instance, 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.
-
Open TerminalTerminalGit Bash.
-
If you have previously configured Git to use a different key format when signing with
--gpg-sign, unset this configuration so the default format ofopenpgpwill be used.git config --global --unset gpg.format -
Use the
gpg --list-secret-keys --keyid-format=longcommand 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.Shell gpg --list-secret-keys --keyid-format=long
gpg --list-secret-keys --keyid-format=longNote: Some GPG installations on Linux may require you to use
gpg2 --list-keys --keyid-format LONGto view a list of your existing keys instead. In this case you will also need to configure Git to usegpg2by runninggit config --global gpg.program gpg2. -
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:Shell $ gpg --list-secret-keys --keyid-format=long /Users/hubot/.gnupg/secring.gpg ------------------------------------ sec 4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10] uid Hubot <hubot@example.com> ssb 4096R/4BB6D45482678BE3 2016-03-10
$ gpg --list-secret-keys --keyid-format=long /Users/hubot/.gnupg/secring.gpg ------------------------------------ sec 4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10] uid Hubot <hubot@example.com> ssb 4096R/4BB6D45482678BE3 2016-03-10 -
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:git config --global user.signingkey 3AA5C34371567BD2Alternatively, when setting a subkey include the