I was installing elasticsearch following this guide, but elasticsearch is not really the part of this question.
In the first step, I need to add the key:
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
and got the following message:
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
The installation process was fine, but since it’s deprecated, I’m looking for the new usage that replaces apt-key
. (I have no problem installing the package.) From man apt-key
I saw
apt-key(8) will last be available in Debian 11 and Ubuntu 22.04.
…
Binary keyring files intended to be used with any apt version should
therefore always be created with gpg –export.
but it didn’t say the alternative to apt-key add
. I tried
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --export
but didn’t work. So what do I use after the pipe of wget
when apt-key
is removed?
10
Answers
!!Deprecated & insecure!!
answer found here :
https://suay.site/?p=526
in short :
retrieve the key and add the key :
authorize the user _apt :
Adding a key to
/etc/apt/trusted.gpg.d
is insecure because it adds the key for all repositories. This is exactly whyapt-key
had to be deprecated.Short version
Do similar to what Signal does.
If you want to use the key at
https://example.com/EXAMPLE.gpg
for a repository listed in/etc/apt/sources.list.d/EXAMPLE.list
, use:Long version
While the deprecation notice recommends adding the key to
/etc/apt/trusted.gpg.d
, this is an insecure solution. To quote this article from Linux Uprising:The proper solution is explained in that Linux Uprising article and on the Debian Wiki: Store the key in
/etc/apt/keyrings/
(or/usr/share/keyrings/
if you’re the package maintainer), and then reference the key in the apt source list.Therefore, the appropriate method is as follows:
https://example.com/EXAMPLE.gpg
and store it in/etc/apt/keyrings/EXAMPLE.gpg
.The Debian wiki explains that you should dearmor the key (i.e. convert it from base64 to binary) for compatibility with older software. The
> /dev/null
simply stops the binary key from being displayed in your terminal.Optionally, you can verify that the file you downloaded is indeed a PGP key by running
file /etc/apt/keyrings/EXAMPLE.gpg
and inspecting the output.Find the appropriate file in
/etc/apt/sources.list.d/
and edit it so that it links to the keyring you just added.If the file doesn’t exist, you can make one.
In the end, it should look something like this:
apt-key
, if it was added before.Run
sudo apt-key list
to list all the keys, and find the one that was previously added.Using the key’s email address or fingerprint, run
sudo apt-key del [email protected]
.Using the newer DEB822 format
In step 2, instead of using the one-line format for sources in
sources.list.d
, you can also use the newer multi-line format called DEB822. This format is easier to read for humans and computers, and has been available in apt since 2015. Debian and Ubuntu plan to use DEB822 as the default format starting late 2023. Repolib’s documentation has a nice comparison and covers the motivation behind the new format.. Note that some external tools that parse the source files themselves instead of wrapping around apt do not fully support this format yet.To switch to this format, let’s say you have the following one-line format source file
/etc/apt/sources.list.d/example.list
:Comment out this line, and create a new file,
/etc/apt/sources.list.d/example.sources
, containing:Run
sudo apt update
, and if you seeexample.com/apt
correctly being updated, you can remove the old/etc/apt/sources.list.d/example.list
.Additional resources
How to add a third-party repo. and key in Debian?
man 5 sources.list
in Ubuntu 22.04 or laterAs mentioned in current accepted answer, adding a key to /etc/apt/trusted.gpg.d is insecure because it adds the key for all repositories. This is why apt-key is giving this warning.
You can use a simpler solution like following:
I got his warning when trying to install nodejs and npm in Ubuntu 20.04
To be more precise:
Instead of this:
Use this:
So the full installtion script looked like this:
MX Linux has a utility script called "MX Fix GPG keys" that takes care of this. Since it’s just a bash script it most likely works fine with any other Debian based distro.
It’s here https://github.com/MX-Linux/checkaptgpg
Experienced this error recently while trying to install Jenkins on my EC2 instance. However, I was able to resolve it by following the steps below:
"wget -q -O – https://pkg.jenkins.io/debian-stable/jenkins.io.key |sudo gpg –dearmor -o /usr/share/keyrings/jenkins.gpg"
You may have to replace jenkins with the package/software you want to install.
"sudo sh -c ‘echo deb [signed-by=/usr/share/keyrings/jenkins.gpg] http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list’"
"apt update"
So apt will use the newly created repo.
Hope this helps :).
Source: https://www.digitalocean.com/community/tutorials/how-to-install-jenkins-on-ubuntu-22-04
Another sample snippet, resolving the issue using updated deb822 format:
In this case, I’m installing k6.io CLI on Ubuntu 22.04 LTS. Adapt as you see fit.
Notice the
.sources
— not.list
!The benefit of deb822 is that the package-signing pubkey gets put inline in the sources-file (and validates only this repo’s packages — which is more secure than trusting it with all other repos).
Being inline in the file saves another
| sudo tee
hoop:Had to whip up the above, because their official instructions got broken yet again.
Fast way to fix this for Linux users with a UI:
Search for the PPA and do
sudo add-apt-repository ppa:[MY_PPA]
(the new PPA with keyring is added automatically and up to date)sudo apt update
Navigate to "Software Sources -> PPA" and delete the old PPA (make sure the new one(s) has/have been added correctly with keyring)
From
man apt-key
(Ubuntu 22.04)This also happens for a poor connection, merely a connection impossible through the port used for download, and to be specific: port 80.
sudo ufw allow port 80
then retry,
this can, for some, help.