Generate a new signing key pair
In this step, you will learn how to generate a new signing key pair using the gpg
command. A signing key pair consists of a private key and a public key. The private key is used to sign data, and the public key is used to verify the signature. This is a fundamental concept in secure communication and software distribution.
First, open your terminal. You are already in the ~/project
directory.
To generate a new key pair, use the following command:
gpg --full-generate-key
After running the command, you will be prompted to select the kind of key you want. For this lab, we will use the default option, which is RSA and RSA
. Press Enter
to accept the default.
gpg (GnuPG) 2.2.27; Copyright (C) 2021 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Please select what kind of key you want:
(1) RSA and RSA (default)
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
Your selection? 1
Next, you will be asked about the keysize. A larger keysize provides more security but takes longer to generate and use. For this lab, we will use the default keysize of 3072 bits. Press Enter
to accept the default.
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (3072)
You will then be asked how long the key should be valid. For this lab, we will make the key valid for one year. Type 1y
and press Enter
.
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) 1y
Confirm that the key will expire on the date shown by typing y
and pressing Enter
.
Key expires at ...
Is this correct? (y/N) y
Now, you need to provide user ID information. This information is associated with your public key and helps others identify you.
First, enter your real name. For this lab, you can use LabEx User
. Type LabEx User
and press Enter
.
Real name: LabEx User
Next, enter your email address. For this lab, you can use [email protected]
. Type [email protected]
and press Enter
.
Email address: [email protected]
You can optionally add a comment. For this lab, you will leave the comment field empty. Press Enter
to skip the comment.
Comment:
Review the information you entered. If it is correct, type O
for Okay and press Enter
. If you need to make changes, type C
for Change or Q
for Quit.
You selected this USER-ID:
"LabEx User <[email protected]>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
Finally, you will be prompted to enter a passphrase to protect your private key. This is a crucial security step. Choose a strong passphrase that you can remember. You will need to enter this passphrase again in the next step.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator more entropy.
The system will then generate the key pair. This may take a moment.