Linux Commands

How to solve gpg: no valid OpenPGP data found error

Using the “wget” or “curl” command, you want to download any application and its key to the apt repository. If you perform both of the specified operations, then you may encounter the “gpg: no valid OpenPGP data found”. Other reasons to consider for the gpg: no valid OpenPGP data found error is that maybe unknowingly you are behind a proxy or CA certificates are not installed on your system or the “curl” command is unable to locate the path of the CA certificates.

This write-up has compiled the most authentic solutions for fixing the “gpg: no valid OpenPGP data found” error. Have a look at the below-given methods and try them one by one on your system

Method 1: Solve gpg: no valid OpenPGP data found error (for wget and curl command)

If you are getting the “gpg: no valid OpenPGP data found” error while executing a “wget” or “curl” command, then the first solution you can try out is to split your command into two parts and then execute them separately.

Let’s say the “wget” command which encountered the error is :

$ wget -q -O - https://www.postgresql.org/media/keys/BAAA3GF9.asc | sudo apt-key add -

For resolving the “gpg: no valid OpenPGP data found” error, firstly download the “BAA3GF9.asc” key separately and then add it to the apt repository.

To get the key file key, we will type out the following command:

$ wget -q -O - https://www.postgresql.org/media/keys/BAAA3GF9.asc

After doing so, we will add the key into the apt repository by adding its filename in the “apt-key” command:

$ sudo apt-key add BAAA3GF9.asc

Similarly, if you have executed a “curl” command with output the “gpg: no valid OpenPGP data found” error, then you have to perform the same split operation on it:

$ curl -O https://www.postgresql.org/media/keys/BAAA3GF9.asc | sudo apt-key add -

Firstly, we will download the key specified in the curl command:

$ curl -O https://www.postgresql.org/media/keys/BAAA3GF9.asc

In the next step, add the downloaded key as a “trusted key” in your “apt” repository in the following way:

$ sudo apt-key add BAAA3GF9.asc

Method 2: Solve gpg: no valid OpenPGP data found error (for wget and curl command)

In case if your company’s security policy has restricted your access to the Internet and deleted the trusted CA or Certificate Authority root certificates, then, you must install the CA Certificates for signing the certificates of the servers with which you need to securely communicate. This solution will also assist you in getting rid of the “gpg: no valid OpenPGP data found” error.

For installing the “CA certificates”, write out below-given command in terminal:

$ sudo apt-get install ca-certificates

Method 3: Solve gpg: no valid OpenPGP data found error (for wget command)

Suppose your organization uses its own certificate and you are behind a corporate proxy. In that case, there exists a possibility to face the “gpg: no valid OpenPGP data found” error while executing the “wget” command. The “–no-check-certificate” option is added in the “wget” command to bypass the verification and continue the download:

For instance, the command which showed us the “gpg: no valid OpenPGP data found” error is:

$ wget -q -O - https://www.postgresql.org/media/keys/BAAA3GF9.asc | sudo apt-key add -

Now, we will add the “–no-check-certificate” option in the same “wget” command:

$ wget --no-check-certificate -q -O - https://www.postgresql.org/media/keys/BAAA3GF9.asc | sudo apt-key add -

Method 4: Solve gpg: no valid OpenPGP data found error (for curl command)

One of the other reasons for the “gpg: no valid OpenPGP data found” error can be the configuration problem of your machine, where the “curl” command is searching for the root CA in the wrong place. To handle the “gpg: no valid OpenPGP data found” error, in this case, you have to fix the CURL certificates path in the “.bashrc” file.

To do so, firstly open up the “.bashrc” file in the nano editor:

$ nano ~/.bashrc

After doing so, add the following line in the opened file and save it:

export CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt

Conclusion

You may encounter “gpg: no valid OpenPGP data found” error when you download a file and try to add its key to your apt repositories at once using the “wget” or “curl” command. Also, if CA certificates are not installed on your system or wrong path is assigned for the CA certificates, then “wget” and “curl” will only output the “gpg: no valid OpenPGP data found” error. In this write-up, we have discussed five different methods for solving the “gpg: no valid OpenPGP data found” error. Try each of them sequentially and be free from the mentioned error.

About the author

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.