Skip to content

Instantly share code, notes, and snippets.

@Cdaprod
Last active June 4, 2024 17:20
Show Gist options
  • Save Cdaprod/b559dfe96c8586ae9aa21a68cdc0ad41 to your computer and use it in GitHub Desktop.
Save Cdaprod/b559dfe96c8586ae9aa21a68cdc0ad41 to your computer and use it in GitHub Desktop.
This guide should help anyone facing APT key issues on their Debian-based systems, including Raspberry Pi OS and CasaOS.

Resolving APT Key Issues on Debian-based Systems

Overview: This guide walks you through fixing the common APT key issues that might occur during package installation on Debian-based systems, such as Raspberry Pi OS. It covers updating system keys, resolving deprecated key issues, and ensuring your system is properly set up to install necessary packages.

Table of Contents:

  1. Introduction
  2. Understanding APT Key Issues
  3. Step-by-Step Fix for APT Key Issues
  4. Conclusion

1. Introduction

APT (Advanced Package Tool) keys are used to authenticate packages and ensure they come from trusted sources. Sometimes, these keys may expire or become deprecated, causing issues during package installation. This guide provides a detailed solution to resolve these key issues.

2. Understanding APT Key Issues

APT keys verify the integrity and authenticity of packages. When a key expires or becomes deprecated, APT cannot verify the packages, leading to errors during updates or installations. Common errors include:

  • The following signatures couldn't be verified because the public key is not available
  • GPG error: The following signatures couldn't be verified

3. Step-by-Step Fix for APT Key Issues

Step 1: Update Your System Ensure your system is up-to-date before making any changes.

sudo apt update && sudo apt upgrade -y

Step 2: Identify the Missing/Deprecated Key When you encounter an APT key error, it usually specifies the missing key. Note down the key ID from the error message.

Example error message:

The following signatures couldn't be verified because the public key is not available: NO_PUBKEY ABCD1234EFGH5678

In this case, ABCD1234EFGH5678 is the key ID.

Step 3: Add the Missing Key Manually Use the apt-key adv command to add the missing key. Replace ABCD1234EFGH5678 with your key ID.

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABCD1234EFGH5678

Step 4: Update the Repository URLs (Optional) Sometimes, the repository URLs might be outdated. Check and update the URLs in your sources list.

Edit your sources list:

sudo nano /etc/apt/sources.list

Ensure the URLs are correct and up-to-date. You can refer to the official repository links provided by the software vendors.

Step 5: Install ca-certificates (Optional) Ensure ca-certificates package is installed and up-to-date.

sudo apt install ca-certificates -y

Step 6: Re-add the Repository and Key (If Required) If the above steps do not resolve the issue, remove and re-add the repository and its key.

Example for a common repository:

  1. Remove the old repository:

    sudo add-apt-repository --remove ppa:repository-name
  2. Re-add the repository:

    sudo add-apt-repository ppa:repository-name
  3. Fetch and install the key manually:

    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABCD1234EFGH5678

Step 7: Update and Upgrade Again After making these changes, update your system again.

sudo apt update && sudo apt upgrade -y

Example of Fixing a Deprecated Key

Here is an example of updating the Docker GPG key:

  1. Remove the old key:

    sudo apt-key del 7EA0A9C3F273FCD8
  2. Add the new key:

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  3. Update the repository:

    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  4. Update and install Docker:

    sudo apt update && sudo apt install docker-ce docker-ce-cli containerd.io -y

4. Conclusion

By following these steps, you can resolve APT key issues on Debian-based systems, ensuring a smooth installation and update process for your packages. This guide provides a comprehensive solution to common APT key problems, helping maintain the integrity and security of your package installations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment