Windows Update 後?に WSL での apt update が失敗するようになった件の対処

発生したのは数カ月前だけど手元にメモが残っていたのでとりあえず公開しておきます。 ちなみに Windows Update がトリガーだったのかすら正確には覚えておらずです。

エラーはこんな内容でした。
なにやら GPG まわりでエラーが発生していた様子です。

1
2
3
4
5
6
7
8
9
10
11
12
13
$ sudo apt update
Get:1 https://packages.microsoft.com/ubuntu/24.04/prod noble InRelease [3600 B]
Err:1 https://packages.microsoft.com/ubuntu/24.04/prod noble InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
Hit:2 http://security.ubuntu.com/ubuntu noble-security InRelease
Hit:3 http://archive.ubuntu.com/ubuntu noble InRelease
Hit:4 http://archive.ubuntu.com/ubuntu noble-updates InRelease
Hit:5 http://archive.ubuntu.com/ubuntu noble-backports InRelease
Reading package lists... Done
W: GPG error: https://packages.microsoft.com/ubuntu/24.04/prod noble InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
E: The repository 'https://packages.microsoft.com/ubuntu/24.04/prod noble InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details

ソース情報のうち、MS のやつを見てみると GPG 鍵のパスが判明しました。

1
2
$ cat /etc/apt/sources.list.d/*.list | grep microsoft
deb [arch=amd64,arm64,armhf signed-by=/usr/share/keyrings/microsoft-prod.gpg] https://packages.microsoft.com/ubuntu/24.04/prod noble main

そのパスにファイルが存在しているのか確認したらなくなっていました。

1
2
$ ll /usr/share/keyrings/microsoft-prod.gpg
ls: cannot access '/usr/share/keyrings/microsoft-prod.gpg': No such file or directory

どこから拾ってきたのか忘れたけど EB3E94ADBE1229CF でググって出てきた MS 公式の情報から、以下を問題のパスに配置する対応となりました。

1
$ curl -sSL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg

これで無事に apt update ができるようになりました。

1
$ sudo apt update