GNU/Linux >> Tutoriales Linux >  >> Cent OS

Cómo generar claves PGP usando GPG en Linux

Cómo generar claves PGP usando GPG en Linux

La aplicación GNU Privacy Guard le permite cifrar y descifrar información, crear claves de cifrado públicas y privadas y usar o verificar firmas digitales. GPG se basa en el uso de un par de claves, una pública y otra privada (o “secreta”). Los datos cifrados con una clave solo se pueden descifrar con la otra. Para encriptar un mensaje para usted, alguien usaría su clave pública para crear un mensaje que solo podría desbloquearse con su clave privada. Para firmar información, la bloquearía con su clave privada, permitiendo que cualquier persona verifique que proviene de usted al desbloquearla con su clave pública.

GPG tiene docenas de opciones adicionales que afinan sus opciones disponibles. En esta publicación veremos cómo generar claves PGP usando GPG en Linux.

Paso 1 :Confirmar versión GPG.

# gpg --help

gpg (GnuPG) 1.4.5
Copyright (C) 2006 Free Software Foundation, Inc.

Paso 2 :Inicie el proceso de generación de claves. Ingresa el siguiente comando para comenzar a generar tu clave:

gpg --gen-key

Select the type of key

Please select what kind of key you want:
(1) DSA and Elgamal (default)
(2) DSA (sign only)
(5) RSA (sign only)      ## SELECT THIS OPTION
Your selection? 5

Select the key size

RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 2048

Requested keysize is 2048 bits

Select the expiration time

Please specify how long the key should be valid.
0 = key does not expire                 ## SELECT THIS OPTION
 = key expires in n days
w = key expires in n weeks
m = key expires in n months
y = key expires in n years
Key is valid for? (0) 0

Key does not expire at all

Is this correct? (y/N) y

Enter user name and email

You need a user ID to identify your key; the software constructs the user ID from the Real Name, Comment and Email Address in this form: 

"[NAME]" (xyz-comment) [USERNAME]@[DOMAIN_NAME].com"

Real name: [Name]
Email address: [USERNAME]@[DOMAIN_NAME].com
Comment: comment
You selected this USER-ID:
"[Name] (comment) [USERNAME]@[DOMAIN_NAME].com"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O

Enter passphrase to protect secret key

You need a Passphrase to protect your secret key.

Enter passphrase: *******
Repeat passphrase: *******

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 a better chance to gain enough entropy.

You may see the following message. If you do, follow the instructions and the key generation process will start automatically.

Not enough random bytes available. Please do some other work to give the OS a chance to collect more entropy! (Need 284 more bytes)

..+++++
...+++++
gpg: key F709C771 marked as ultimately trusted
public and secret key created and signed

gpg: checking the trustdb
gpg: 3 marginal(s) needed. 1 complete(s) needed, PGP trust model
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0m, 0n, 0f, 1u
pub: 2048R/F709C771 2015-05-27
key fingerprint = BDC2 5293 DB14 C218 D2DA 711C EB0A 564A F709 C771
uid [Name] (comment) [USERNAME]@[DOMAIN_NAME].com

Tenga en cuenta que esta clave no se puede utilizar para el cifrado. Es posible que desee utilizar el comando “–edit-key ” para generar una subclave para este propósito. La generación de claves está completa. En este punto, ha generado un par de claves pública/privada con una clave pública que se puede utilizar para fines de firma. El siguiente paso es agregar una subclave que se usará para el cifrado.

Paso 3 :agrega una subclave para el cifrado. Ingresa el siguiente comando para comenzar a generar tu clave:

# gpg --edit-key '[NAME]'
gpg (GnuPG) 1.4.5; Copyright (C) 2006 Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the file COPYING for details.

Secret key is available.

pub 2048R/F709C771 created: 2015-05-27 expires: never usage: SC
trust: ultimate validity: ultimate
[ultimate] (1). [Name] (comment) [USERNAME]@[DOMAIN_NAME].com

Enter the edit-key command

Command> addkey

Key is protected.

Enter the passphrase you specified in step 2

You need a passphrase to unlock the secret key for
user: "[NAME] (comment) [USERNAME]@[DOMAIN_NAME].com"
2048-bit RSA key, ID F709C771, created 2015-05-27

Enter passphrase: *******

user: "[Name] (comment) [USERNAME]@[DOMAIN_NAME].com"
2048-bit RSA key, ID F709C771, created 2015-05-27

Select the type of key

Please select what kind of key you want:
(2) DSA (sign only)
(4) Elgamal (encrypt only)
(5) RSA (sign only)
(6) RSA (encrypt only)              ## SELECT THIS OPTION
Your selection? 6

Select the key size

RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 2048

Requested keysize is 2048 bits

Select the expiration time

Please specify how long the key should be valid.
0 = key does not expire       ## SELECT THIS OPTION
 = key expires in n days
w = key expires in n weeks
m = key expires in n months
y = key expires in n years
Key is valid for? (0) 0

Key does not expire at all
Is this correct? (y/N) Y
Really create? (y/N) Y

Necesitamos generar muchos bytes aleatorios. Es una buena idea realizar alguna otra acción (escribir en el teclado, mover el mouse, utilizar los discos) durante la generación principal; esto le da al generador de números aleatorios una mejor oportunidad de ganar suficiente entropía.

Es posible que vea el siguiente mensaje. Si lo hace, siga las instrucciones y el proceso de generación de la subclave se iniciará automáticamente.

Not enough random bytes available. Please do some other work to give the OS a chance to collect more entropy! (Need 277 more bytes)

..........+++++
..........+++++

pub 2048R/F709C771 created: 2015-05-27 expires: never usage: SC
trust: ultimate validity: ultimate
sub 2048R/13DA9D02 created: 2015-05-27 expires: never usage: E
[ultimate] (1). [Name] (comment) [USERNAME]@[DOMAIN_NAME].com

Note, pub is for signing (SC), sub is for encryption (E)

Exit the edit-key editor and save your changes

Command> q
Save changes? (y/N) y

La generación de subclaves para fines de cifrado está completa. El siguiente paso es verificar y exportar las claves.

Paso 4 :Haz una lista de tus llaves. Ingrese el siguiente comando para enumerar la clave en su conjunto de claves:

# gpg -k
/home/[USERNAME]/.gnupg/pubring.gpg
--------------------------------
pub 2048R/F709C771 2015-05-27
uid Your [NAME] (comment) [USERNAME]@[DOMAIN_NAME].com
sub 2048R/13DA9D02 2015-05-27

Paso 5 – Exportar la clave pública (incluida la subclave) en formato ASCII. Ingrese el siguiente comando para enumerar las claves:

# gpg --armor --output [Name]-pub-sub.asc --export '[Name]'
# cat [NAME]-pub-sub.asc

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.5 (GNU/Linux)

“[.......Removed the PGP KEY...... ]”

-----END PGP PUBLIC KEY BLOCK-----


Cent OS
  1. Cómo configurar claves SSH usando cPanel

  2. ¿Cómo generar una clave SSH en un servidor dedicado de Linux?

  3. Cómo generar una solicitud de firma de certificado (CSR) en Linux

  4. ¿Cómo convertir un archivo PPK a claves OpenSSH e iniciar sesión usando SSH en Linux?

  5. Cómo crear (y publicar) una clave PGP en Linux usando una GUI

Cómo generar una clave SSH en CentOS 8

Cómo configurar claves SSH en Debian 11 Linux

Cómo generar y usar una clave SSH usando PuTTY

¿Cómo generar y usar la clave SSH en el sistema Linux?

Genere claves RSA con SSH usando PuTTYgen

Cómo generar una clave fuerte precompartida en Linux