A repository's GPG signing key has expired, causing apt to reject package signatures as invalid. This commonly occurs when third-party repositories like MongoDB, MySQL, or Yarn are not actively maintained or have not renewed their GPG keys.
This error occurs when the APT package manager validates repository signatures using GPG (GNU Privacy Guard) keys. Each Linux repository signs its packages with a GPG key to prove authenticity and integrity. When a repository's GPG key expires, APT rejects the signature as invalid because the key can no longer be trusted. This is a security mechanism that prevents using packages signed with outdated or potentially compromised keys. The error typically appears during `apt-get update` when checking third-party repositories added via PPAs or manual sources.
Look at the complete error output to find the key ID. The error will mention something like KEYEXPIRED 1544811256. Note this key ID or the repository URL mentioned in the error.
apt-get update 2>&1 | grep -i keyexpiredThis will isolate the GPG error and show you which repository is affected.
In rare cases, an incorrect system clock can make valid keys appear expired. Verify the current date and time:
dateIf the date is significantly in the past, update it using NTP:
sudo timedatectl set-ntp trueOr set it manually (format: YYYY-MM-DD HH:MM:SS):
sudo timedatectl set-time "2025-12-29 14:30:00"Visit the official website of the software (e.g., mongodb.com, mysql.com) and look for Ubuntu/Debian installation instructions. These usually include commands to add the GPG key. This ensures you get the latest, non-expired key.
For example, the official MongoDB installation guide at mongodb.com/docs/manual/tutorial/install-mongodb-on-debian/ contains the current key URL.
First, remove the expired key file if it exists:
sudo rm /etc/apt/trusted.gpg.d/[repository-name].gpgThen download and add the updated key from the official source:
sudo wget https://[official-key-url] -O /etc/apt/trusted.gpg.d/[repository-name].gpgFor example, to update the MySQL key:
sudo rm /etc/apt/trusted.gpg.d/mysql.gpg
sudo wget https://repo.mysql.com/RPM-GPG-KEY-mysql-2023/ -O /etc/apt/trusted.gpg.d/mysql.gpgMake sure the key file has proper permissions:
sudo chmod 644 /etc/apt/trusted.gpg.d/[repository-name].gpgIf you have the key ID from the error message, you can refresh it directly from Ubuntu's keyserver:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys [KEY_ID]Replace [KEY_ID] with the actual ID from the error. For example:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 871920D1991BC93CNote: On newer Ubuntu/Debian systems (20.04+), apt-key is deprecated. Use the method in step 4 (downloading the key file directly) instead.
List the installed keys to confirm:
sudo apt-key listOr check the trusted.gpg.d directory:
ls -la /etc/apt/trusted.gpg.d/Now update your repositories:
sudo apt-get updateThe GPG error should be resolved. You can now install or upgrade packages normally.
Modern Ubuntu/Debian (20.04+) prefer GPG keys stored in /etc/apt/trusted.gpg.d/ as individual .gpg files rather than the legacy /etc/apt/trusted.gpg keyring, which is deprecated. When a repository provides a .key file, you should convert it to .gpg format using gpg --dearmor before placing it in trusted.gpg.d/. Some repositories like Veeam and NVIDIA require specific key management procedures; always check their official documentation. If a third-party repository is no longer maintained and updating the key is not possible, remove it from your sources list: edit /etc/apt/sources.list.d/[repository-name].list and delete the line, then run apt-get update again.
E: Could not connect to proxy server
Could not connect to proxy server
E: Package 'package:i386' has no installation candidate
How to fix "Package package:i386 has no installation candidate" in apt
E: The value 'value' is invalid for APT::Default-Release
How to fix invalid APT::Default-Release value in APT
dpkg: error: unable to create new file 'path': Permission denied
How to fix dpkg permission denied errors in APT
subprocess installed post-removal script returned error exit status 1
How to fix "subprocess installed post-removal script returned error exit status 1" in APT