[7 Proven Fixes] “gpg: no valid OpenPGP data found”

Written by

Reviewed by

Last updated: July 24, 2024

Expert verified

SVG Image

TL;DR

To fix the “gpg: no valid OpenPGP data found” error on your Linux system, try these solutions:

  1. Fix the Outdated Software: Ensure GPG is up-to-date using sudo apt update && sudo apt upgrade, then restart with gpgconf –kill gpg-agent && gpgconf –reload gpg-agent.
  2. Check for Improperly Formatted or Corrupted Files: Verify files with gpg –list-packets filename.gpg and re-import using gpg –import publickey.asc.
  3. Install CA Certificates: Install CA certificates with sudo apt update && sudo apt install ca-certificates.
  4. Change the Path in the .bashrc File: Add export CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt to .bashrc and save changes.

Learn more about how to fix the “gpg: no valid OpenPGP data found” error in the detailed guide below.

Running into errors can be really frustrating, especially when you’re in the middle of something important. If you’ve seen the “gpg: no valid OpenPGP data found” error, don’t worry—there’s a way to fix it. This post will help you solve this problem with easy steps. We’ll cover how to update your software, check for corrupted files, and set up key servers correctly. By the end, you’ll know exactly what to do to fix this error and keep it from happening again.

What is the gpg: no valid OpenPGP data found Error?

The gpg: no valid OpenPGP data found error happens when you try to import a PGP key using GPG (GNU Privacy Guard), but GPG can’t find any valid key data in the file or URL you provided. This means the key file might be:

  • Corrupt
  • Incorrectly formatted
  • Incomplete

Alternatively, there might be a problem with the URL where the key is located.

How to Fix the gpg: no valid OpenPGP data found Error

To fix the “gpg: no valid OpenPGP data found” error, start by updating your GPG software. Use the command sudo apt update && sudo apt upgrade to ensure you have the latest version. Then, restart GPG with gpgconf --kill gpg-agent && gpgconf --reload gpg-agent. This should resolve the issue.

Here’s the detailed step-by-step guide for this method and six other methods to fix the “gpg: no valid OpenPGP data found” error:

1. Fix the Outdated Software

Make sure both GPG and OpenPGP software are up-to-date and compatible to avoid or fix the “gpg: no valid OpenPGP data found” error. Here are the steps to update GPG and OpenPGP:

  1. Check the newer version of GPG by running the command: 
sudo apt update && sudo apt upgrade
  1. To install the newer version of GPG, use the command:
sudo apt install gnupg
  1. After running these commands, you’ll have this output:
steps to update gpg and openpgp
  1. Now, restart GPG with the following commands:
gpgconf --list-dirs
gpgconf --kill gpg-agent
gpgconf --reload gpg-agent

Alternatively, you can use this command to restart GPG:

sudo systemctl restart gpg
command to restart gpg
  1. Now, try decrypting or verifying the OpenPGP data again.
gpg -c filename.extension
  1. Once you execute this command, you’ll have to enter the passphrase for this file.
enter passphrase to decrypt or verify
  1. If the command is successful, you’ll see the following output:
output of passphrase

2. Check for Improperly Formatted or Corrupted Files

Sometimes, you may see the “gpg: no valid OpenPGP data found” error when the files are corrupt or improperly formatted. If that’s the case, follow these steps: 

  1. Check if the file is complete and not corrupted by running the command:
gpg --list-packets filename.extension.gpg
  1. Enter the passphrase that you had entered for this file to let the Terminal read the packets.
passphrase to check if file is courrpted
  1. You’ll see the following output:
output for command to check if file corrupted
  1. If the file is corrupted, try downloading it from a trusted source again. But if the file is complete but encrypted with a different public key, obtain the correct public key and import it into GPG using the command: 
gpg --import publickey.asc

3. Install CA Certificates

If you are experiencing the “gpg: no valid OpenPGP data found” error while using GPG, installing the CA certificate onto your system can help to resolve the issue. This is because GPG relies on digital certificates to authenticate and encrypt messages, and the absence or corruption of these certificates can cause this error message to appear. To install the CA certificate on your system, you can follow these steps:

  1. Execute the following code to install CA certificates:
sudo apt update && sudo apt install ca-certificates
  1. Wait for the update and the new CA certificate installation process to complete.
ca certificate installation process
  1. If your Linux packages and CA certificates are already updated and installed on your system, you will see a message indicating this on your Terminal.
already installed ca certificate 1

4. Change the Path in the .bashrc File

If the “gpg: no valid OpenPGP data found” error is caused by the computer looking for the CA certification in the wrong path, you can change the path in the .bashrc file. 

  1. Use the following command to open the .bashrc file executable script file:
nano ~/.bashrc
  1. Once the file opens, add the following command to it:
export CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
  1. Press Ctrl + O to save the file and Ctrl + X to exit the nano editor.
ca certification in wrong path error
  1. This command will add the correct path to the file, and the “gpg: no valid OpenPGP data found” error should no longer occur.

5. Refresh the Keyring

To fix the “gpg: no valid OpenPGP data found” error, try refreshing the keyring. To do this, you have to:

  1. Execute the following command in the Terminal app:
gpg --refresh-keys
  1. Wait for the refreshing process to complete.
refreshing the keyring gpg: no valid OpenPGP data found error
  1. Once this process is complete, try to decrypt the file or verify the OpenPGP signature and check if the error is resolved.

6. Verify the Keyring Settings

Ensure that the keyring settings are correct. Follow the steps below to verify the keyring settings:

  1. In the Terminal app, enter the following command:
gpg --list-keys
  1. You’ll see the list of gpg keys stored on your Linux system.
verify keyring settings
  1. If you see an error message, the keyring settings are incorrect. To fix the settings, enter the following command:
gpg --recv-keys <key-id>

Replace <key-id> with the correct ID for your key.

7. Incorrect GPG Keyserver Configuration

Another reason for the “gpg: no valid OpenPGP data found” error is the incorrect GPG keyserver configuration. To ensure that it is properly configured, follow these steps:

  1. Check the keyserver settings by running the command:
gpg --version
  1. Look for the Home entry in the output and note the location of the configuration file.
incorrect keyserver configuration
  1. Now, check the current keyserver settings by running the following command:
gpgconf --list-options gpg | grep keyserver
  1. This command will display the current keyserver settings in the Terminal Window.
check current keyserver settings
  1. If the keyserver settings are wrong or outdated, update it with the command below while replacing the /.gnupg with the path to your GPG home directory:
gpgconf --homedir ~/home/farah/.gnupg --kill all && gpgconf --homedir /home/farah/.gnupg  --reload gpg
  1. To verify that the keyserver settings have been updated to the default keyserver, run the following command:
gpgconf --list-options gpg | grep keyserver
  1. You’ll see the following output:
update and verify keyserver settings

7 Tips to Prevent “gpg: no valid OpenPGP data found” Error

To prevent the “gpg: no valid OpenPGP data found” error from occurring in the future, it’s important to follow best practices. Here are some of them to consider:

  • 🔑 Keep keyring settings and GPG up-to-date: Update the keyring settings so that GPG can find the necessary key to decrypt files and verify OpenPGP signatures. You can run sudo apt-get update && sudo apt-get install gnupg to update the package list and install the GnuPG package. Then, execute gpg --refresh-keys to fetch the latest public key updates from the key server.
  • 🔍 Verify OpenPGP data before decryption: Verify the validity of OpenPGP data before decrypting a file to prevent corrupted or invalid data issues, including the “gpg: no valid OpenPGP data found” error. You can run gpg --verify <filename> to verify the OpenPGP data.
  • 💾 Keep a backup of the keyring: Use gpg --export-secret-keys > mykeyring_backup.asc to keep a backup of the keyring. This command will export your secret keys and save them to a file named “mykeyring_backup.asc” in your current working directory. You can then copy this file to a secure location..
  • 🔑 Use reputable keyservers for public keys: To ensure key authenticity, it’s important to use reputable keyservers to obtain public keys. Some examples of reputable keyservers include keyserver.ubuntu.com and keys.openpgp.org.
  • 🛡️ Check GPG keys and files before use: Before using GPG keys and files, it’s important to verify that they’re not corrupted. This can help prevent issues related to corrupted files, which may cause the “gpg: no valid OpenPGP data found” error. You can use the gpg --check-sigs <filename> command to check the GPG keys and files.
  • 🔒 Use trusted sources for OpenPGP data: To prevent issues related to malicious data, only use trusted sources when obtaining OpenPGP data. It can help you to avoid the “gpg: no valid OpenPGP data found” error due to the use of untrusted data.

To Sum Up

In this article, I’ve covered several methods to fix the “gpg: no valid OpenPGP data found” error. I also discussed updating outdated software, checking for improperly formatted or corrupted files, installing CA certificates, and refreshing the keyring.

If you want to learn more, here are a few additional readings you might find helpful:

Frequently Asked Questions

What is the relationship between OpenPGP and GPG?

OpenPGP is a standard that defines a set of methods for encrypting and signing data using public key cryptography. GPG, or GNU Privacy Guard, is a popular and widely used implementation of this standard. GPG provides a free and open-source software solution for encrypting and signing data, allowing users to secure their sensitive information.

Can I encrypt and sign emails using GPG?

Yes, GPG can be used to encrypt and sign emails. A variety of email clients, including Microsoft Outlook and Thunderbird, offer plugins that enable the use of GPG for email encryption and signing. By using GPG to encrypt and sign emails, you can ensure that your communications are secure and that only the intended recipient can read the content.

Is GPG the sole encryption software available for Linux systems?

No, Linux systems have a variety of encryption software options available. In addition to GPG, popular encryption software for Linux includes Libsodium, NaCl, and OpenSSL, among others. Each option provides different features and benefits, so choosing the encryption software that best fits your needs is important.

Can the “gpg: no valid OpenPGP data found” error harm my system?

Typically, “gpg: no valid OpenPGP data found” error is the software-related issue and do not cause any harm to your system. But if you are working with sensitive data, it is critical to ensure that your encryption software is operating correctly to prevent any security breaches. So, if you experience GPG errors, it is important to troubleshoot and resolve them promptly to ensure that your encrypted data remains secure. 

Ojash

Author

Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.

Akshat

Reviewer

Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

Share this article
Shareable URL
Prev Post

5 Simple Ways to Fix “sub-process /usr/bin/dpkg returned an error code (1)”

Next Post

3 Quick Ways to Fix the “wget command not found” Error

Leave a Reply

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

Read next