How to generate PGP keys using GPG on Linux

Getting your PGP public and private keys was never easy. Available manuals were written in language average person is not able to understand. Here is the simple way of creating your public and private PGP keys on a Linux based machine (vm or physical).

To complete this tutorial, you will need following:

Linux based machine (virtual or physical)
GPG version minimum 1.4.5

To check what version of GPG you run on your Linux machine, run the following command:

gpg --help

The very fist line will show you the program version, in my case 1.4.18

gpg (GnuPG) 1.4.18
Copyright (C) 2014 Free Software Foundation, Inc.

Use the following command to start generating your keys (Please note that the recommended answers and commands you need to run are printed in red color):

Now we generate the initial key:

gpg --gen-key

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? 4
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) <- Accept the default value by clicking Enter

Requested keysize is 2048 bits
Please specify how long the key should be valid.
 0 = key does not expire
  = 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) <- Accept the default value by clicking Enter

Key does not expire at all
Is this correct? (y/N) y
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:
 "Heinrich Heine (Der Dichter) "

Real name: Emir Sef
Email address: emir@sefnet.local
Comment:
You selected this USER-ID:
 "Emir Sef "

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.

Enter passphrase: ********
Repeat passphrase: ********
......+++++
....+++++
gpg: key 7E873EC2 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: 2 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 2u
pub 2048R/7E873EC2 2016-08-23
 Key fingerprint = C56C 72BE B3E0 1D1E FF86 DA98 0F1F 1C1B 7E87 3EC2
uid Emir Sef 

Note that this key cannot be used for encryption. You may want to use
the command "--edit-key" to generate a subkey for this purpose.

 

gpg --edit-key 'Emir Sef'

gpg (GnuPG) 1.4.18; Copyright (C) 2014 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.

Secret key is available.

pub 2048R/7E873EC2 created: 2016-08-23 expires: never usage: SC
 trust: ultimate validity: ultimate
[ultimate] (1). Emir Sef 
gpg> addkey

Key is protected.

You need a passphrase to unlock the secret key for
user: "Emir Sef "
2048-bit RSA key, ID 7E873EC2, created 2016-08-23


Enter passphrase: ******** <- Password you have earlier created
Please select what kind of key you want:
 (3) DSA (sign only)
 (4) RSA (sign only)
 (5) Elgamal (encrypt only)
 (6) RSA (encrypt only)
Your selection? 6
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) <- Accept the default value by clicking Enter

Requested keysize is 2048 bits
Please specify how long the key should be valid.
 0 = key does not expire
  = 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) <- Accept the default value by clicking Enter

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

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

pub   2048R/7E873EC2    created: 2016-08-23    expires: never    usage: SC
                        trust: ultimate        validity: ultimate
sub   2048R/D13546D9    created: 2016-08-23    expires: never usage: E
[ultimate] (1). Emir Sef 
gpg> q
Save changes? (y/N) y
gpg -k


/root/.gnupg/pubring.gpg
------------------------
pub 2048R/7E873EC2 2016-08-23
uid Emir Sef 
sub 2048R/D13546D9 2016-08-23
gpg --armor --output emirsef-pub-sub.asc --export 'Emir Sef'
cat emirsef-pub-sub.asc

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1

mQENBFe8BY0BCAC/reY7Vg0KFn3KVqFrJTU4bYavMHT2ReImiVTlgB98dG4oXz9e
BmHPLN+xTSLaaFaNTkYRPb2mb1hBk2VzJ9nTW9Il6SC/Q6/kJSgCZdT72NM3kAgL
kSw5iXN4Om5aGRDL6wJLWGSAYJYnpVZEOTK8NsPYOuPGLsZnI2+Y99Y2eAJIvsz1
HyvlxTpDB0/pvV4EOtSsmjR7RlrO7uE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FtDorwSW6oRsW/YXpGXVaEm01i9iJtE8ii
H0dT3BMDQVR0cCDyb+2b1ENInvBAvLkBDQRXvDfVAQgAzJg6h/sv2tQtTn9N9qhU
qpDKTXGyR+LwKZFb8IGa0UWlMShhE4lURdLDCpzea29mlr0dpBaFO2Ji+S47Wnwb
6IkItKBkIt/9JvXsNs3JujqDw/0ic+S7S12mA5eH7bUxdSoROr8PUSfo/FF4QiW1
hK290VnUKNx3mTFMW5DAPqPupaEUnW+TjXE7DA817kXnRvpKVSSsLdiu7GUsyo0K
ROsv2Qkw2FB48EENAThnyLDv8OojKEvbqgixfjJnelPyEz0qAUnJIOzPmMH/faLg
paqU5e9/1kmUqWwmjWm6TqtPA+XW7G9rbEY1zcYYtt/6bJ8N06l47zy18G4IgEEK
EQARAQABiQEfBBgBAgAJBQJXvDfVAhsMAAoJEA8fHBt+hz7C7fwH/2hmyRYeVTMw
ADLyEu+3n5+rpTrM0TEWOgWEybgZdUw/A39NNezLy7axfteuYbE5ITrnLbzATaQt
mEIgQ7rjLthH9M+Msa4Sc00aWdzWDZEOXMg+znrqEQz4R66ue4pP8A29/QZo/Ypw
/+qeC3ZY4qkno2SIt6GozMMnnLJ7FD6fAOMpwAFTxCSyaowKk6h2puJ0czuP+GrT
a+qLyYYsm7xDoxrpn/ricxMwoLoAY/xl6jGkzTDuzQ5qJvqaV9JOg0o63OMb9u/x
pj0PnHBDsaEpwN16Tu1xci/jUy/HjZmRWPqR4MD6APWoruvdVImCYPwgvCnl2PKn
dkCW5CzV1+Q=
=OuQQ
-----END PGP PUBLIC KEY BLOCK-----

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.