GrepBoard/매뉴얼
605 편 ·

Key is stored in legacy trusted.gpg 해결

·시험 환경 Ubuntu 24.04 · apt 2.8.3 · gpg 2.4.4 (Docker) · 2026-10·시험 범위 ↓·6 단계

apt 의 Key is stored in legacy trusted.gpg 경고는 키가 옛 공용 키링에 있다는 뜻입니다. /etc/apt/keyrings 로 꺼내 signed-by 로 묶고 옛 키를 지웁니다.

output
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.

apt-key add 로 넣은 저장소 키가 옛 공용 키링 /etc/apt/trusted.gpg 에 들어 있어서 나는 경고입니다. 업데이트는 성공하지만, 그 키를 그 저장소 전용 파일로 꺼내 signed-by= 로 묶어 주면 사라집니다. 맨페이지는 apt-key 가 Ubuntu 24.04 를 끝으로 빠진다고 적고 있어(apt-key(8)) 다음 판으로 올리기 전에 정리해 두는 편이 낫습니다.

[1] 경고 줄의 주소로 어느 저장소인지 봅니다. 위에서는 file:/srv/repo 이고, 실제로는 https://packages.example.com/... 같은 외부 저장소 주소가 찍힙니다. 그다음 옛 키링에 어떤 키가 있는지 봅니다.

console
# 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>

/etc/apt/trusted.gpg 아래에 나온 키가 대상입니다. /etc/apt/trusted.gpg.d/ubuntu-keyring-*.gpg 는 Ubuntu 자체 키이므로 건드리지 않습니다.

[2] 그 키를 전용 파일로 꺼냅니다. 맨페이지는 APT 2.4 부터 패키지가 관리하지 않는 키를 두는 곳으로 /etc/apt/keyrings 를 권합니다. 지문은 [1]에서 본 값을 공백 없이 씁니다.

console
# 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] 저장소 줄에 signed-by= 를 붙여 그 키로만 검증하게 합니다. 한 줄 형식(.list)이면 이렇게 바꿉니다.

console
# cat /etc/apt/sources.list.d/example.listdeb [signed-by=/etc/apt/keyrings/example.gpg] file:/srv/repo ./

Ubuntu 24.04 의 기본 저장소가 쓰는 deb822 형식(.sources)이면 Signed-By: 줄입니다. 이 형식으로 옮기면 기존 .list 는 지우고 하나만 둡니다.

/etc/apt/sources.list.d/example.sources
Types: debURIs: file:/srv/repoSuites: ./Signed-By: /etc/apt/keyrings/example.gpg

[4] apt update 를 다시 돌려 경고가 사라졌는지 봅니다. 이 시점에는 옛 키가 아직 /etc/apt/trusted.gpg 에 남아 있어도 경고가 나오지 않았습니다. signed-by 가 있으면 apt 가 그 파일만 보기 때문입니다.

console
# apt-get updateGet:1 file:/srv/repo ./ InRelease [1524 B]Get:1 file:/srv/repo ./ InRelease [1524 B]Reading package lists...

[5] 옛 키링에서 그 키를 지웁니다. 경고가 사라졌다고 끝내면 옛 키는 여전히 signed-by 가 없는 모든 저장소의 서명을 믿는 데 쓰입니다. 다만 /etc/apt/trusted.gpg 는 공용이라, 같은 키를 쓰는 다른 저장소가 아직 signed-by 없이 남아 있으면 지우는 순간 그 저장소가 끊깁니다. 지우기 전에 두 가지를 합니다.

먼저 경고가 하나도 남지 않았는지 봅니다. 아래는 같은 키로 서명된 두 번째 저장소(repo2)를 signed-by 없이 남겨 둔 상태입니다. 이렇게 한 줄이라도 나오면 그 저장소에도 [3]을 먼저 합니다.

console
# 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.

모든 저장소를 옮긴 뒤에는 0 이 나와야 합니다.

console
# apt-get update 2>&1 | grep -c 'legacy trusted.gpg'0

그다음 옛 키링을 통째로 백업합니다. 되돌릴 때 이 파일을 씁니다.

console
# 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.bak

이제 지웁니다. 아래는 지문 끝 8자리로 지운 것이고, 끝 8자리는 다른 키와 겹칠 수 있으므로 [1]의 전체 지문(공백 없이)을 써도 됩니다(전체 지문으로도 OK 를 확인). 맨페이지는 apt-key 사용을 폐기로 두면서 패키지 관리 스크립트의 apt-key del 만 예외로 적고 있고, Ubuntu 24.04 에서는 명령이 아직 들어 있습니다.

console
# 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)).OK

지운 뒤에 apt update 가 NO_PUBKEY 로 실패하는 원인은 셋입니다. ① 위처럼 같은 키를 쓰던 다른 저장소가 signed-by 없이 남아 있었다 ② [3]의 signed-by 경로가 틀렸다 ③ 키 파일이 비어 있다(gpg --show-keys 로 다시 확인). 아래는 키 파일을 지운 상태에서 본 실패입니다. 이 상태에서는 그 저장소의 새 패키지 목록을 받지 못하므로 바로 고칩니다.

output
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] 남은 키가 없는지 봅니다. 마지막 키를 지우면 /etc/apt/trusted.gpg 파일 자체가 없어졌습니다.

console
# ls -l /etc/apt/trusted.gpgls: cannot access '/etc/apt/trusted.gpg': No such file or directory

apt 가 잠금 오류로 멈추면 apt dpkg lock-frontend 글을 봅니다.

#apt#apt-key#gpg#signed-by#keyring