After adding a new apt repository to your sources.list you often get a gpg error that there is no public key for that repository. If you trust the added server you can add the key with the command stated below.
Here is an example error message. I replaced the id of the key with <long_key>:
“GPG error: http://archive.ubuntu.com oneiric Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY <long_key>”
And here is how to import the key:
gpg --keyserver keyserver.ubuntu.com --recv-keys <long_key> gpg --export --armor <long_key> | sudo apt-key add -
Update 2023: apt-key has been deprecated. You can try to replace this by
KEY=<long_key>
NAME=<name_for_the_key>
gpg --keyserver keyserver.ubuntu.com --recv-keys $KEY
gpg --export --armor $KEY | sudo tee /etc/apt/trusted.gpg.d/${NAME}.asc
In case it isn’t automatically picked up from that location you need to add the following to your /etc/apt/sources.list entry:
signed-by=/etc/apt/trusted.gpg.d/docker.gpg]
Here a full sample:
# cat /etc/apt/sources.list.d/docker.list
deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/docker.gpg] https://download.docker.com/linux/ubuntu jammy stable
This way you can place your gpg files wherever you want because you’re putting the path to the key into your config.