跳到主要内容

Generating GPG Public Key

GPG (GNU Privacy Guard) public keys are essential tools for encrypting and verifying data. They can be used to protect your email communications, verify the integrity of software packages, and sign documents.

The process of obtaining GPG public keys varies slightly across different operating systems. Below are detailed steps for Windows, macOS, and Linux systems:

Getting GPG Public Key on Windows System

Installing GPG

  1. Visit the official Gpg4win website to download the Gpg4win installation package.
  2. Run the downloaded installer and follow the prompts to complete the installation.

Generating and Exporting GPG Public Key

Open Command Prompt or PowerShell, then use the following commands:

Generate a new GPG key pair (if you don't have one yet):

gpg --full-generate-key

Follow the page prompts to generate the GPG key:

Please select what kind of key you want:
(1) RSA and RSA
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
(9) ECC (sign and encrypt) *default*
(10) ECC (sign only)
(14) Existing key from card
Your selection? 1 // It is recommended to choose an RSA and RSA type key
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (3072) 4096 // For security, it is recommended to set the length to 4096
Requested keysize is 4096 bits
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
Key is valid for? (0) // Configure the validity period of the GPG key as needed
Key does not expire at all
Is this correct? (y/N) y // Confirm the configuration again
GnuPG needs to construct a user ID to identify your key.

Real name: gitcode // Configure your name
Email address: email@gitcode.com // Configure your email address, note that the email must match the default email on GitCode
Comment:
You selected this USER-ID:
"gitcode <email@gitcode.com>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o // If no changes are needed, a password prompt will appear next, enter the password and continue

List GPG keys to find your public key ID:

gpg --list-keys

Export GPG public key (replace YOUR_KEY_ID with your public key ID):

gpg --armor --export YOUR_KEY_ID

Generating and Exporting GPG Public Key via Software

In addition to the above command-line method, you can also create and export GPG public keys using the Kleopatra software installed just now. Note that the email must match the default email on GitCode.

Getting GPG Public Key on macOS System

Installing GPG Suite

  1. Visit the official GPG Suite website to download GPG Suite.
  2. Open the downloaded .dmg installation package and follow the prompts to complete the installation.

Generating and Exporting GPG Public Key

Open Terminal, then use the following commands:

Generate a new GPG key pair (if you don't have one yet):

gpg --full-generate-key

Follow the page prompts to generate the GPG key:

Please select what kind of key you want:
(1) RSA and RSA
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
(9) ECC (sign and encrypt) *default*
(10) ECC (sign only)
(14) Existing key from card
Your selection? 1 // It is recommended to choose an RSA and RSA type key
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (3072) 4096 // For security, it is recommended to set the length to 4096
Requested keysize is 4096 bits
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
Key is valid for? (0) // Configure the validity period of the GPG key as needed
Key does not expire at all
Is this correct? (y/N) y // Confirm the configuration again
GnuPG needs to construct a user ID to identify your key.

Real name: gitcode // Configure your name
Email address: email@gitcode.com // Configure your email address, note that the email must match the default email on GitCode
Comment:
You selected this USER-ID:
"gitcode <email@gitcode.com>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o // If no changes are needed, a password prompt will appear next, enter the password and continue

List GPG keys to find your public key ID:

gpg --list-keys

Export GPG public key (replace YOUR_KEY_ID with your public key ID):

gpg --armor --export YOUR_KEY_ID

Generating and Exporting GPG Public Key via Software

In addition to the above command-line method, you can also create and export GPG public keys using the GPG Keychain software installed just now. Note that the email must match the default email on GitCode.

Getting GPG Public Key on Linux System

On most Linux distributions, GPG is usually pre-installed. If not installed, you can install GPG via the package manager.

Installing GPG

  • For Debian-based systems (such as Ubuntu):

    sudo apt-get install gnupg
  • For RPM-based systems (such as Fedora):

    sudo dnf install gnupg

Generating and Exporting GPG Public Key

Open Terminal, then use the following commands:

Generate a new GPG key pair (if you don't have one yet):

gpg --full-generate-key

Follow the page prompts to generate the GPG key:

Please select what kind of key you want:
(1) RSA and RSA
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
(9) ECC (sign and encrypt) *default*
(10) ECC (sign only)
(14) Existing key from card
Your selection? 1 // It is recommended to choose an RSA and RSA type key
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (3072) 4096 // For security, it is recommended to set the length to 4096
Requested keysize is 4096 bits
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
Key is valid for? (0) // Configure the validity period of the GPG key as needed
Key does not expire at all
Is this correct? (y/N) y // Confirm the configuration again
GnuPG needs to construct a user ID to identify your key.

Real name: gitcode // Configure your name
Email address: email@gitcode.com // Configure your email address, note that the email must match the default email on GitCode
Comment:
You selected this USER-ID:
"gitcode <email@gitcode.com>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o // If no changes are needed, a password prompt will appear next, enter the password and continue

List GPG keys to find your public key ID:

gpg --list-keys

Export GPG public key (replace YOUR_KEY_ID with your public key ID):

gpg --armor --export YOUR_KEY_ID

Configuring GPG Public Key on GitCode Platform

Now that you have successfully obtained your GPG public key, you can configure this GPG public key on GitCode to encrypt communication or verify signatures.

Click on the top right corner 【User Avatar】-【Personal Settings】-【Public Key Management】-【GPG Public Key】 to configure the GPG public key.

Note that the GPG email must match the current user's added email to pass the verification.