Generating a GPG Public Key
A GPG (GNU Privacy Guard) public key is an important tool used for encrypting and verifying data. It can be used to protect your email communications, verify the integrity of software packages, and sign documents.
The process of obtaining a GPG public key varies slightly across different operating systems. Below are detailed steps for Windows, macOS, and Linux systems:
Getting a GPG Public Key on Windows
Installing GPG
- Visit the official Gpg4win website to download the Gpg4win installation package.
- Run the downloaded installer and follow the prompts to complete the installation.
Generating and Exporting a 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 the 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 use a length of 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, 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 the configuration remains unchanged, a password input box will pop up, enter the password and continue
List GPG keys to find your public key ID:
gpg --list-keys
Export the GPG public key (replace YOUR_KEY_ID
with your public key ID):
gpg --armor --export YOUR_KEY_ID
Generating and Exporting a GPG Public Key via Software
In addition to the command line method above, you can also create and export a GPG public key using the recently installed Kleopatra software, ensuring that the email matches the default email on GitCode.
Getting a GPG Public Key on macOS
Installing GPG Suite
- Visit the official GPG Suite website to download GPG Suite.
- Open the downloaded
.dmg
installation package and follow the prompts to complete the installation.
Generating and Exporting a 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 the 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 use a length of 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, 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 the configuration remains unchanged, a password input box will pop up, enter the password and continue
List GPG keys to find your public key ID:
gpg --list-keys
Export the GPG public key (replace YOUR_KEY_ID
with your public key ID):
gpg --armor --export YOUR_KEY_ID
Generating and Exporting a GPG Public Key via Software
In addition to the command line method above, you can also create and export a GPG public key using the recently installed GPG Keychain software, ensuring that the email matches the default email on GitCode.
Getting a GPG Public Key on Linux
In most Linux distributions, GPG is usually pre-installed. If not, 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 a 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 the 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 use a length of 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, 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 the configuration remains unchanged, a password input box will pop up, enter the password and continue
List GPG keys to find your public key ID:
gpg --list-keys
Export the GPG public key (replace YOUR_KEY_ID
with your public key ID):
gpg --armor --export YOUR_KEY_ID
Configuring a GPG Public Key on the GitCode Platform
-
Log in to GitCode, go to "Personal Settings" -> "Security Settings" -> "GPG Public Key"
-
Click “+ GPG Public Key”
-
In the “Public Key Name” field, add a descriptive name for the public key
-
Paste the exported GPG public key into the “Public Key” text box
-
Click “Create” to complete the operation
-
An "Verified" message indicates successful creation
Now, you have successfully obtained your GPG public key and can configure this GPG public key on GitCode to encrypt communication or verify signatures.
Note that the GPG email must match the current user's verified email to pass validation.