Generate a GPG Key
If you don't have an existing GPG key, you can generate a new GPG key to use for signing commits and tags.
Supported GPG key algorithms
GitHub supports several GPG key algorithms. If you try to add a key generated with an unsupported algorithm, you may encounter an error.
- RSA
- ElGamal
- DSA
- ECDH
- ECDSA
- EdDSA
Note: Before generating a new GPG key, make sure you've configured your name & email address. If you haven't configured your name & email address, you won't be able to sign commits and tags with GPG. For more information, see GIT Configuration page
Make sure you've downloaded and installed the GPG command line tools for your operating system. We generally recommend installing the latest version for your operating system.
- Windows
- macOS
- Linux/Unix
Generating a GPG Key in Windows
Please follow the Step-by-step guide detailed below, to generate a GPG Key in Windows operating systems
-
Open Git Bash
-
Generate a GPG key pair. Since there are multiple versions of GPG, you may need to consult the relevant man page to find the appropriate key generation command.
- If you are on version 2.1.17 or greater, paste the text below to generate a GPG key pair.
Generate Keygpg --full-generate-key
- If you are not on version 2.1.17 or greater, the gpg
--full-generate-key
command doesn't work. Paste the text below and skip to step 5.
Legacy Supportgpg --default-new-key-algo rsa4096 --gen-key
-
At the prompt, specify the kind of key you want, or press
Enter
to accept the default. -
At the prompt, specify the key size you want, or press
Enter
to accept the default. -
Enter the length of time the key should be valid. Press
Enter
to specify the default selection, indicating that the key doesn't expire. Unless you require an expiration date, we recommend accepting this default. -
Verify that your selections are correct.
-
Enter your user ID information.
When asked to enter your email address, ensure that you enter the verified email address for your GitHub account. To keep your email address private, use your GitHub-provided no-reply email address. For more information, see "Verifying your email address" and "Setting your commit email address."
-
Type a secure passphrase.
-
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.List Secret Keysgpg --list-secret-keys --keyid-format=long
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 usegpg2
by 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
:GPG Key ID$ 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 -
Paste the text below, substituting in the GPG key ID you'd like to use. In this example, the GPG key ID is
3AA5C34371567BD2
:Print GPG Keygpg --armor --export 3AA5C34371567BD2
-
Copy your GPG key, beginning with
-----BEGIN PGP PUBLIC KEY BLOCK-----
and ending with-----END PGP PUBLIC KEY BLOCK-----
.
Generating a GPG Key in macOS
Please follow the Step-by-step guide detailed below, to generate a GPG Key in macOS
-
Open Terminal
-
Generate a GPG key pair. Since there are multiple versions of GPG, you may need to consult the relevant man page to find the appropriate key generation command.
- If you are on version 2.1.17 or greater, paste the text below to generate a GPG key pair.
Generate Keygpg --full-generate-key
- If you are not on version 2.1.17 or greater, the gpg
--full-generate-key
command doesn't work. Paste the text below and skip to step 5.
Legacy Supportgpg --default-new-key-algo rsa4096 --gen-key
-
At the prompt, specify the kind of key you want, or press
Enter
to accept the default. -
At the prompt, specify the key size you want, or press
Enter
to accept the default. -
Enter the length of time the key should be valid. Press
Enter
to specify the default selection, indicating that the key doesn't expire. Unless you require an expiration date, we recommend accepting this default. -
Verify that your selections are correct.
-
Enter your user ID information.
When asked to enter your email address, ensure that you enter the verified email address for your GitHub account. To keep your email address private, use your GitHub-provided no-reply email address. For more information, see "Verifying your email address" and "Setting your commit email address."
-
Type a secure passphrase.
-
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.List Secret Keysgpg --list-secret-keys --keyid-format=long
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 usegpg2
by 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
:GPG Key ID$ 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 -
Paste the text below, substituting in the GPG key ID you'd like to use. In this example, the GPG key ID is
3AA5C34371567BD2
:Print GPG Keygpg --armor --export 3AA5C34371567BD2
-
Copy your GPG key, beginning with
-----BEGIN PGP PUBLIC KEY BLOCK-----
and ending with-----END PGP PUBLIC KEY BLOCK-----
.
Generating a GPG Key in Linux/Unix
Please follow the Step-by-step guide detailed below, to generate a GPG Key in Linux/Unix
-
Open Terminal
-
Generate a GPG key pair. Since there are multiple versions of GPG, you may need to consult the relevant man page to find the appropriate key generation command.
- If you are on version 2.1.17 or greater, paste the text below to generate a GPG key pair.
Generate Keygpg --full-generate-key
- If you are not on version 2.1.17 or greater, the gpg
--full-generate-key
command doesn't work. Paste the text below and skip to step 5.
Legacy Supportgpg --default-new-key-algo rsa4096 --gen-key
-
At the prompt, specify the kind of key you want, or press
Enter
to accept the default. -
At the prompt, specify the key size you want, or press
Enter
to accept the default. -
Enter the length of time the key should be valid. Press
Enter
to specify the default selection, indicating that the key doesn't expire. Unless you require an expiration date, we recommend accepting this default. -
Verify that your selections are correct.
-
Enter your user ID information.
When asked to enter your email address, ensure that you enter the verified email address for your GitHub account. To keep your email address private, use your GitHub-provided no-reply email address. For more information, see "Verifying your email address" and "Setting your commit email address."
-
Type a secure passphrase.
-
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.List Secret Keysgpg --list-secret-keys --keyid-format=long
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 usegpg2
by 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
:GPG Key ID$ 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 -
Paste the text below, substituting in the GPG key ID you'd like to use. In this example, the GPG key ID is
3AA5C34371567BD2
:Print GPG Keygpg --armor --export 3AA5C34371567BD2
-
Copy your GPG key, beginning with
-----BEGIN PGP PUBLIC KEY BLOCK-----
and ending with-----END PGP PUBLIC KEY BLOCK-----
.