Profile picture

[Linux] apt-key is deprecated. Manage keyring files in trusted.gpg.d instead

JaehyoJJAng2024년 12월 10일

문제 상황

apt-key add 명령어로 *.gpg 파일을 등록했는데 다음과 같은 경고문이 발생하였음.

Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).

해당 경고 메시지는 apt-key 명령어가 더 이상 권장되지 않으며,

대신 /etc/apt/trusted.gpg.d 디렉토리에 직접 GPG 키를 관리하라는 의미이다.



apt-key는 향후 버전에서 제거될 예정이므로, 새로운 방식으로 등록하는 방법에 대해서 기록해보겠다.


해결 방법

예를 들어, 특정 GPG 키 URL이 있다고 가정해보자.

https://example.com/repo.gpg

이 키를 trusted.gpg.d에 등록하려면 다음과 같이 한다.

curl -fsSL https://example.com/repo.gpg | gpg --dearmor -o /etc/apt/trusted.gpg.d/example-repo.gpg
  • curl로 키 다운로드
    • -fsSL 옵션은 실패 시 오류 없이 깨끗한 출력을 보장.
  • ASCII 형식의 GPG 키를 바이너리로 변환.
    • gpg --dearmor
  • /etc/apt/trusted.gpg.d/에 저장
    • 키 파일 이름은 .gpg 확장자 필수.

예시: Docker 저장소 키 등록

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/docker.gpg

문제 상황 2: 기존 키 파일 유효성 문제

elastic.filebeat 설치 도중 다음과 같은 에러가 발생하였음.

W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: https://artifacts.elastic.co/packages/8.x/apt stable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY D27....
W: Failed to fetch https://artifacts.elastic.co/packages/8.x/apt/dists/stable/InRelease  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY D27....
W: Some index files failed to download. They have been ignored, or old ones used instead.

해당 경고문을 요약하면 "Elastic 저장소의 공개 키가 시스템에 등록되지 않아서 패키지 서명을 검증할 수 없다."라고 함.


그러나 GPG 키의 경우 이미 등록되어있는 상태.


해결 방법

  • GPG 키는 유효성, 경로 일치, 형식, 권한 등이 맞아야 제대로 동작함.

1. 키 파일 이름이 다름

기존: /usr/share/keyrings/elasticsearch-keyring.gpg

새로 생성한 것: /usr/share/keyrings/elastic-keyring.gpg


APT는 sources.list.d/*.list에 정의된 signed-by=... 경로와 정확히 일치하는 .gpg 키를 사용함.


👉 만약 저장소 정의에 signed-by=/usr/share/keyrings/elastic-keyring.gpg라고 되어 있는데, 시스템에는 elasticsearch-keyring.gpg만 있다면 키가 존재해도 무시됩니다.


2. 키 내용이 오래되었거나 손상됐을 수 있음

예전 버전의 키가 elasticsearch-keyring.gpg에 저장되어 있었을 수 있어요.

Elastic은 종종 GPG 키를 갱신하거나 재배포하는데, 예전 키를 계속 쓰고 있으면 오류가 납니다.

NO_PUBKEY D27....은 시스템이 해당 키 ID를 모르겠다는 뜻이에요. 즉, 기존 키에 해당 ID가 포함되지 않았을 가능성이 높아요.


Loading script...