Fix apt "Key is stored in legacy trusted.gpg keyring" warning
apt warns "Key is stored in legacy trusted.gpg" when a repo key is in the old shared keyring. Export it to /etc/apt/keyrings, add signed-by, delete the old key.
W: file:/srv/repo/./InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.The repository key was added with apt-key add and lives in the old shared keyring /etc/apt/trusted.gpg. The update still succeeds, but the warning goes away once you move the key into a file for that repository and bind it with signed-by=. The man page says apt-key will last be available in Ubuntu 24.04 (apt-key(8)), so clean this up before the next release upgrade.
[1] Read the repository URL in the warning line. Here it is file:/srv/repo; on a real system it is an external URL such as https://packages.example.com/.... Then list the keys in the legacy keyring.
# apt-key listWarning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8))./etc/apt/trusted.gpg--------------------pub rsa3072 2026-10-26 [SC] 7E03 6446 E59B F3A7 8252 E741 20E9 8699 E8DE EF69uid [ unknown] Example Repo <repo@example.com>The keys under /etc/apt/trusted.gpg are the ones to move. Leave /etc/apt/trusted.gpg.d/ubuntu-keyring-*.gpg alone — those are Ubuntu's own keys.
[2] Export that key to its own file. The man page names /etc/apt/keyrings (since APT 2.4) as the recommended place for keys not managed by packages. Use the fingerprint from [1] without spaces.
# install -d -m 0755 /etc/apt/keyrings && gpg --no-default-keyring --keyring /etc/apt/trusted.gpg --export 7E036446E59BF3A78252E74120E98699E8DEEF69 > /etc/apt/keyrings/example.gpg && ls -l /etc/apt/keyrings/total 4-rw-r--r-- 1 root root 901 Oct 26 21:27 example.gpg# gpg --show-keys /etc/apt/keyrings/example.gpgpub rsa3072 2026-10-26 [SC] 7E036446E59BF3A78252E74120E98699E8DEEF69uid Example Repo <repo@example.com>[3] Add signed-by= to the repository line so apt verifies it with that key only. For the one-line format (.list):
# cat /etc/apt/sources.list.d/example.listdeb [signed-by=/etc/apt/keyrings/example.gpg] file:/srv/repo ./For the deb822 format (.sources) that Ubuntu 24.04's own sources use, it is a Signed-By: line. If you switch to this format, delete the old .list and keep just one.
Types: debURIs: file:/srv/repoSuites: ./Signed-By: /etc/apt/keyrings/example.gpg[4] Run apt update again and check that the warning is gone. In the test, it disappeared even while the old key was still in /etc/apt/trusted.gpg, because with signed-by apt looks only at that file.
# apt-get updateGet:1 file:/srv/repo ./ InRelease [1524 B]Get:1 file:/srv/repo ./ InRelease [1524 B]Reading package lists...[5] Delete the key from the legacy keyring. If you stop when the warning disappears, the old key is still trusted for every repository without signed-by. But /etc/apt/trusted.gpg is shared: if another repository signed with the same key still has no signed-by, deleting the key cuts that repository off. Do two things first.
Check that no warning is left. Below, a second repository (repo2) signed with the same key was left without signed-by. If even one line like this appears, do [3] for that repository too.
# apt-get update 2>&1 | grep 'legacy trusted.gpg'W: file:/srv/repo2/./InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.Once every repository is moved, the count must be 0.
# apt-get update 2>&1 | grep -c 'legacy trusted.gpg'0Then back up the whole legacy keyring. This is the file you restore from.
# cp -a /etc/apt/trusted.gpg /root/trusted.gpg.bak && ls -l /root/trusted.gpg.bak-rw-r--r-- 1 root root 901 Oct 26 22:19 /root/trusted.gpg.bakNow delete it. The example uses the last 8 characters of the fingerprint; since a short ID can collide with another key, you can pass the full fingerprint from [1] without spaces instead (the full form also returned OK in the test). The man page deprecates apt-key except for apt-key del in package maintainer scripts, and the command is still shipped in Ubuntu 24.04.
# apt-key --keyring /etc/apt/trusted.gpg del E8DEEF69Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).OKIf apt update then fails with NO_PUBKEY, there are three causes: (1) another repository using the same key was left without signed-by, as above; (2) the signed-by path from [3] is wrong; (3) the key file is empty (check again with gpg --show-keys). The failure below was produced by deleting the key file. In this state apt cannot fetch new package lists for that repository, so fix it right away.
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: file:/srv/repo ./ InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 20E98699E8DEEF69[6] Check that nothing is left. After the last key was deleted, the /etc/apt/trusted.gpg file itself was gone.
# ls -l /etc/apt/trusted.gpgls: cannot access '/etc/apt/trusted.gpg': No such file or directoryIf apt stops on a lock error, see apt dpkg lock-frontend.