How to Encrypt and Decrypt with PGP on Linux

Encrypt and decrypt with PGP on Linux and enjoy solid messaging security even without getting yourself clouded with unwanted complexities. PGP, aka Pretty Good Privacy, just how it is named, can help make encryption a seamless encounter.

Now that you’ve bagged the necessary information, let’s shift our attention and learn how to encrypt and decrypt with PGP on Linux. The entire process is a bit lengthy, so to make sure the procedure is presented in the most easy-to-digest manner, I’ve sectioned the tutorial into the following steps:

Step 1: Downloading and Installing the Encryption Tool

The first step is installing the required encryption tool on your system. Here is how you can do it:

Launch the Terminal by using the “Ctrl+Alt+T” key combination.

Run the sudo apt install command inside the Terminal.


$ sudo apt-get install gapgnupg2
install pgp tool

If your system is password-protected, you’ll need to input your password and press the “Enter” key.

After that, the system will ask for confirmation whether you’ve got the required space inside the drive or not. Type “Y” then hit the “Enter” key, and wait for a few minutes until the process concludes.

Step 2: Building the PGP Key Pair

Once you’ve installed the tool, the next step is to build the PGP key pair. For your information, PGP uses two different keys termed ‘public’ and ‘private’. While one encrypts an email message, the other decrypts it.

Launch the Terminal

Use the “Ctrl+Alt+T” key combination to launch the Terminal.

Invoke the Key Command

Run the gpg -gen -key command inside the Terminal.

invoke the key command

Choosing the RSA Key

After invoking the command mentioned above, you’ll be ready to choose the length of the RSA key. Remember the length is around 1024 to 4096 bits long (more length means more level of security).

choose the RSA

Set the Validity

The next step is assigning the key’s validity period. Here, you’ll learn how to set the date (or time) of expiry. Simply pass the desired value, and you’re done. If you want the key to bear a lifetime validity, input 0.

Confirm the Changes

Input “Y” and press the “Enter” key to validate your selection.

Create an ID

Creating an ID is crucial as it helps the other parties identify your key. The user ID usually gets generated based on the concerned user’s real name, email address, or similar credentials. Press the “O key” once you’re satisfied with the same.

Protecting the Key with Password

You’ll then come across a screen on whether you’ll be allowed to set a password for your key. Do the requisites and move forward.

Generate the Key

Now you’re ready to generate the key. You can either type anything on your keyboard or just move your mouse around to get the job done.

Step 3: Grabbing the Public Key

Since you’ve generated your own RSA key you’re now ready to obtain the public key. Here is how you can do it:

  • Launch the Terminal and invoke the following command:
$ sudo gpa
grabbing the pubic key
  • Head over and input your passphrase.
  • Entering the passphrase will launch the GPA key manager window. Make sure not to close this window until you’re done with the process.
  • Navigate to the list and highlight all the created PGP keys.
  • After that, hover over to the menu and tap the ‘Keys” option.
  • From there, select the Export option.
  • Pick the desired location and hit the Save button. You can now open the saved text file with an editor.

Step 4: Grabbing the Private Key

Once you’re done with the public key, follow the steps mentioned below and obtain the private key.

While you’re inside the GPA Key Manager tool, locate and click on the pair of keys. Hit the “Keys” tab one more time, but opt for backup instead of clicking the Export option. Choose the location and save the file. Ensure you don’t bring any changes to the name of the file.

Step 5: Importing the Public Key

To import the public key, get it first from the concerned recipient. You can either get in touch with the person for this purpose or have a look at their profile. As soon as you have it, get inside the text editor and copy-paste everything. 

encrypt and decrypt with pgp

Head over to the GPA Key Manager, hit the “Keys” tab, and click on the “Import” option. Select the copied key and tap “Open”. Repeat the same process for getting the private key imported.

Step 6: Encrypting and Decrypting the Message

Arriving at this point, you’ve successfully concluded all the requisites. With that being said, you can now learn how to encrypt and decrypt with PGP on Linux.

Encrypting the Message

Launch GPA and open the “Windows” tab. Find and open the Clipboard window by tapping on the dedicated option and input the desired message that you want to encrypt. After that, head over to the menu again and click on the “Envelope icon” (one with the blue key), select the receiving medium, and sign the created message with your key.

Hit the “Ok” option, and you’re done.

encrypt and decrypt with pgp

Decrypting the Message

Here is how the receiver needs to proceed in order to decrypt and access the message.

Click and open the encrypted message, copy and paste the same inside the GPA clipboard window. Once done, hit the envelope icon that carries the yellow key. Finally, input the created passphrase, and that’s it.

And that marks the end of this article. We hope you spent time reading the entire write-up as it covers all the required information in encrypting and decrypting with PGP on Linux in the most user-friendly manner.

If this guide helped you, please share it.

Leave a Reply
Related Posts