Skip to content

Creating a GPG Key

Create and upload a GPG key.

Generating a GPG key

1. Install a GPG Command Line Tool

Download and install the GPG command line tools for your operating system.

2. Open Git Bash

3. Generate a GPG key pair

For version 2.1.17 or greater, use the following command.

gpg --full-generate-key
  • Follow the prompts to create the kind of key you want. I recommend using an RSA and RSA key with a keysize of 4096 and setting the expiry to 0.
  • Verify that your selections are correct.
  • When prompted, type a secure passphrase. This can be anything, although I recommend against using spaces.
Note

For versions less than 2.1.17, use this commmand.

gpg --default-new-key-algo rsa4096 --gen-key

4. Find your key ID

List the long form of the GPG keys for which you have both a public and private key.

 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.

You'll see something like:

pub   rsa4096/ABC123DEF4567890 2025-01-01 [SC]

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

Tip

Print your key in ASCII armor format with this command.

gpg --armor --export ABC123DEF4567890

5. Publish Your Public Key

Upload your key to a keyserver.

gpg --keyserver hkps://keys.openpgp.org --send-keys ABC123DEF4567890
  • Replace ABC123DEF4567890 with your actual key ID.

1. Install a GPG Command Line Tool

Download and install the GPG command line tools for your operating system.

2. Open Terminal

3. Generate a GPG key pair

For version 2.1.17 or greater, use the following command.

gpg --full-generate-key
  • Follow the prompts to create the kind of key you want. I recommend using an RSA and RSA key with a keysize of 4096 and setting the expiry to 0.
  • Verify that your selections are correct.
  • When prompted, type a secure passphrase. This can be anything, although I recommend against using spaces.
Note

For versions less than 2.1.17, use this commmand.

gpg --default-new-key-algo rsa4096 --gen-key

4. Find your key ID

List the long form of the GPG keys for which you have both a public and private key.

 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.

You'll see something like:

pub   rsa4096/ABC123DEF4567890 2025-01-01 [SC]

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

Tip

Print your key in ASCII armor format with this command.

gpg --armor --export ABC123DEF4567890

5. Publish Your Public Key

Upload your key to a keyserver.

gpg --keyserver hkps://keys.openpgp.org --send-keys ABC123DEF4567890
  • Replace ABC123DEF4567890 with your actual key ID.

1. Install a GPG Command Line Tool

Download and install the GPG command line tools for your operating system.

2. Open Terminal

3. Generate a GPG key pair

For version 2.1.17 or greater, use the following command.

gpg --full-generate-key
  • Follow the prompts to create the kind of key you want. I recommend using an RSA and RSA key with a keysize of 4096 and setting the expiry to 0.
  • Verify that your selections are correct.
  • When prompted, type a secure passphrase. This can be anything, although I recommend against using spaces.
Note

For versions less than 2.1.17, use this commmand.

gpg --default-new-key-algo rsa4096 --gen-key

4. Find your key ID

List the long form of the GPG keys for which you have both a public and private key.

 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.

You'll see something like:

pub   rsa4096/ABC123DEF4567890 2025-01-01 [SC]

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

Tip

Print your key in ASCII armor format with this command.

gpg --armor --export ABC123DEF4567890

5. Publish Your Public Key

Upload your key to a keyserver.

gpg --keyserver hkps://keys.openpgp.org --send-keys ABC123DEF4567890
  • Replace ABC123DEF4567890 with your actual key ID.