How to solve an expired key (KEYEXPIRED) with apt

Ankit Kumar Rajpoot
2 min readFeb 2, 2020

You’ll maintain your system now and then and update installed packages to keep your system secure.

This error happens when your system installs services from third-party repositories as we do with MongoDB.

Recently, while maintaining the software on our server, we ran apt-get update then we find this error during updating.

You see that there is some error related to the expired key.

Now, you will find all the expired keys via this command.

$ sudo apt-key list | grep “expired: ”

After running this command you will see all the expired commands. 4096R/EA312927 in this section after the /, remains part is the key.

Now, we will recover the keys one by one via this command.

$ sudo apt-key adv --keyserver keys.gnupg.net --recv-keys [key]

After recovering key, update command should work, But if some case it doesn’t work and again you find the same problem. Then there is another solution. you should delete that key via this command.

$ sudo apt-key del [key]

After deleting when you run $ sudo apt-get update you will find an error that key is not available then you should have to add key via the following command.

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys [key]

After running that command, you will see there are no expired keys. Now, you can run $ sudo apt-get update the command for the update.

Keep up-to-date your server.🤓

Feel free to ask any questions or queries in the comment section or you can ping me on Facebook.

--

--

Ankit Kumar Rajpoot

I’m a MERN Developer. ( Redux | AWS | Python ) I enjoy taking on new things, building skills, and sharing what I’ve learned.