The Wayback Machine - https://web.archive.org/web/20240715075409/https://www.geeksforgeeks.org/how-to-generate-pgp-keys-using-gnupg-on-linux/
Open In App

How to generate PGP keys using GnuPG on Linux?

Last Updated : 02 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Linux is a family of open-source operating systems and comes as various distributions or distros. GnuPG or GPG is free software that allows users to encrypt and sign their data and communications. It is based on PGP also called Pretty Good Privacy. It is used to generate PGP keys and can generate public and private keys. The generated PGP keys will have cryptographic features.

PGP Keys are of two types: public and private. The data is encrypted using the public keys and later for decryption, the private keys are used.

In this article, we will learn three different methods for generating keys that are:

  • –gen-key: This option helps in generating PGP keys and saves the revocation certificate in the “/root/.gnugp/” directory. 
  • –full-gen-key: This option is the user-friendly method that permits the generation of the PGP keys in batch mode and accesses the options provided in the dialogue.
  • –quick-gen-key: This option offers a quick process of generating the PGP keys and requires only userid and the rest of the settings as the default options.

Installing GPG on Linux

For this tutorial, the Ubuntu distro is used. Open the terminal by pressing CTRL+Alt+T together or normally by the applications tray and then enter the following command.

sudo apt install gnupg -y

On successful installation, the output will be as follows:

 

Method 1: Generating PGP keys using the –gen-key option

To generate a PGP key with the –gen-key option, enter the following command in Terminal.

sudo gpg --gen-key

Now you need to enter your details as asked such as name, email id, etc. Then press O to confirm. 

 

In the next step, enter a paraphrase. This will be used for encrypting the private key.

 

 Then confirm it again by typing the same.

 

Finally, you should get the following output:

 

The revocation certificate is saved in the /root/.gnugp/openpgp-revocs.d directory. Also the pub id, uid and sub are shown on the screen.

Method 2: Generating PGP keys using the –full-gen-key option

Enter the following command to generate –full-gen-key:

sudo gpg --full-generate-key

In the terminal, it will ask for the type of encryption. The following are the different types:

  • RSA and RSA(default): The encryption key will be public and the decryption key will be kept private. 
  • DSA and Elgamal: DSA is an algorithm based on digital signing and verification, and the Elgamal uses asymmetric encryption for communication.

Type 1 to choose the first option for this tutorial.

 

Then enter your details and the paraphrase and the output will be the same.

 

Method 3: Generate PGP keys with –quick-gen-key

Enter the following command for the –quick-gen-key. Replace the [userid] with your id.

sudo gpg --quick-gen-key [userid] 

Then press Y to continue and enter the paraphrase.

 

Finally, the output looks as follows:

 

List PGP keys with the GPG command 

Enter the following command to list the PGP keys.

gpg -k

The output is as follows:

 



Similar Reads

Encrypting and Decrypting the Files Using GnuPG in Linux
GnuPG is an encryption module that uses OpenPGP at its core. PGP stands for Pretty Good Privacy. It is an encryption program that provides authentication and cryptographic privacy for data communication. In the age where data is the new oil, the modern age thieves won't intrude in through doors, windows or roofs, but instead, via wires and electric
3 min read
Kali Linux Shortcut Keys
Kali Linux (formerly known as Backtrack Linux) is an open-source Debian-derived Linux distribution designed primarily for digital forensics and penetration testing. It serves as a specialized operating system used by cybersecurity professionals and ethical hackers to assess the security of computer systems. Kali Linux comes preloaded with a variety
6 min read
How to Generate a Self-Signed Certificate with OpenSSL in Linux?
TLS (Transport Layer Security) is a secured protocol which is currently in trend. It can see used on top of the HTTP and application layer. The primary use of this protocol is to set up secure communication between web applications and servers. TLS protocol can also be used for secure email transfer, messaging and voice over IP. Why SSL/TLS secure
3 min read
PhishMailer – Generate Professional Phishing Alert Templates in Kali Linux
PhishMailer is a powerful open-source Phishing Tool. PhishMailer is becoming very popular nowadays that is used to do phishing attacks on Target. PhishMailer is easier than Social Engineering Toolkit. PhishMailer contains some templates generated by another tool called PhishMailer. PhishMailer offers phishing templates web pages for 10 popular site
3 min read
How To Generate SSH Key With ssh-keygen In Linux?
Secure Shell(SSH) is a cryptographic network protocol used for operating remote services securely. It is used for remote operation of devices on secure channels using a client-server architecture that generally operates on Port 22. SSH is the successor of Telnet. SSH uses public and private keys to validate and authenticate users. ssh-keygen is use
4 min read
How to Generate Database Dump of MySQL Database in Linux?
We will learn how to Backup and Restore your MySQL Database with Mysqldump query in LINUX. We had always a need that if the production database is corrupted somehow, we should be able to recover it, for recovering we should always keep a backup of the database at particular instances. So, data rollback can be done. First, we will create a Database
2 min read
Ipdump - Generate a Report for hostname Ipaddress URL or domain in Kali Linux
Ipdump is free and open-source available on GitHub. This tool can retrieve IP or Domain Geolocation, Whois information, closed and open ports details. Features of Ipdump:Ipdump can be used to retrieve Geolocation information.Ipdump can be used to fetch the SSL certification of a domain.Ipdump can be used to get WHOIS information of IP addresses and
2 min read
Terminalizer : Record Your Linux Terminal and Generate Animated GIF
Terminalizer is an open-source cross-platform CLI tool that is used to record the terminal session and generate or share animated gif images. FeaturesChange background, title, font, colors, window frames, transition speed.Share your recording on the webAdd watermark In this article, we will show you how to install terminalizer in Debian-based Linux
2 min read
How to generate SSH Key Fingerprint in Linux?
A popular protocol for safe remote access to servers and other systems is called Secure Shell (SSH). The SSH key fingerprint is one of the essential elements of SSH authentication. We will discuss the definition of an SSH key fingerprint, its creation process, its significance for SSH authentication, and security and verification issues in this art
8 min read
How to Generate a CSR (Certificate Signing Request) in Linux?
Certificate Signing Request(CSR) is a block encrypted text which is given to Certificate Authority when applying for SSL Certificate. Generation of Certificate Signing Request(CSR) for Secure Sockets Layer(SSL) is common in Linux on various distributions. CSR is generated on the server, it stores information relating to the organization, domain nam
5 min read
Article Tags :