![无法通过 apt-key 导入 GPG 密钥](https://linux22.com/image/1207592/%E6%97%A0%E6%B3%95%E9%80%9A%E8%BF%87%20apt-key%20%E5%AF%BC%E5%85%A5%20GPG%20%E5%AF%86%E9%92%A5.png)
我正在尝试在我的 Ubuntu 20.04 服务器上安装 mono。
我按照官方的安装说明进行Mono
操作下载
执行时:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
出现以下错误:
Executing: /tmp/apt-key-gpghome.l2rhGqvMmi/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
gpg: keyserver receive failed: No such file or directory
在类似的问题中,我发现可以通过运行 strace 获得更多见解。以下是 strace 的输出。我不得不删减一些中间输出,以符合帖子字符限制:
execve("/usr/bin/apt-key", ["apt-key", "adv", "--keyserver", "hkp://keyserver.ubuntu.com:80", "--recv-keys", "3FA7E0328081BFF6A14DA29AA6A19B38"...], 0x7ffc2afa5c18 /* 13 vars */) = 0
brk(NULL) = 0x55e6a789c000
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffc1557cd50) = -1 EINVAL (Invalid argument)
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=63853, ...}) = 0
mmap(NULL, 63853, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f1cd10ad000
close(3) = 0
[...]
read(3, "/etc/apt/trusted.gpg.d/ubuntu-ke"..., 128) = 55
read(3, "", 128) = 0
close(3) = 0
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 19223
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=19223, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
rt_sigreturn({mask=[]}) = 19223
openat(AT_FDCWD, "/tmp/apt-key-gpghome.nBHDrgCJ0q/pubring.gpg", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3
fcntl(1, F_DUPFD, 10) = 11
close(1) = 0
fcntl(11, F_SETFD, FD_CLOEXEC) = 0
dup2(3, 1) = 1
close(3) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f1cd10ac850) = 19224
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 19224
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=19224, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
rt_sigreturn({mask=[]}) = 19224
dup2(11, 1) = 1
close(11) = 0
wait4(-1, 0x7ffc1557bfac, WNOHANG, NULL) = -1 ECHILD (No child processes)
faccessat(AT_FDCWD, "/tmp/apt-key-gpghome.nBHDrgCJ0q/pubring.gpg", R_OK) = 0
stat("/usr/local/sbin/cp", 0x7ffc1557c600) = -1 ENOENT (No such file or directory)
stat("/usr/local/bin/cp", 0x7ffc1557c600) = -1 ENOENT (No such file or directory)
stat("/usr/sbin/cp", 0x7ffc1557c600) = -1 ENOENT (No such file or directory)
stat("/usr/bin/cp", {st_mode=S_IFREG|0755, st_size=153976, ...}) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f1cd10ac850) = 19225
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 19225
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=19225, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
rt_sigreturn({mask=[]}) = 19225
pipe([3, 4]) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f1cd10ac850) = 19226
close(4) = 0
read(3, "/tmp/apt-key-gpghome.nBHDrgCJ0q/"..., 128) = 41
read(3, "", 128) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=19226, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
rt_sigreturn({mask=[]}) = 0
close(3) = 0
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 19226
pipe([3, 4]) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f1cd10ac850) = 19229
close(4) = 0
read(3, "/tmp/apt-key-gpghome.nBHDrgCJ0q/"..., 128) = 44
read(3, "", 128) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=19229, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
rt_sigreturn({mask=[]}) = 0
close(3) = 0
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 19229
openat(AT_FDCWD, "/tmp/apt-key-gpghome.nBHDrgCJ0q/gpg.1.sh", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
fcntl(1, F_DUPFD, 10) = 11
close(1) = 0
fcntl(11, F_SETFD, FD_CLOEXEC) = 0
dup2(3, 1) = 1
close(3) = 0
write(1, "#!/bin/sh\nexec sh '/tmp/apt-key-"..., 122) = 122
dup2(11, 1) = 1
close(11) = 0
write(1, "Executing: /tmp/apt-key-gpghome."..., 147Executing: /tmp/apt-key-gpghome.nBHDrgCJ0q/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
) = 147
stat("/usr/local/sbin/sh", 0x7ffc1557c700) = -1 ENOENT (No such file or directory)
stat("/usr/local/bin/sh", 0x7ffc1557c700) = -1 ENOENT (No such file or directory)
stat("/usr/sbin/sh", 0x7ffc1557c700) = -1 ENOENT (No such file or directory)
stat("/usr/bin/sh", {st_mode=S_IFREG|0755, st_size=129816, ...}) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f1cd10ac850) = 19232
wait4(-1, gpg: keyserver receive failed: No such file or directory
[{WIFEXITED(s) && WEXITSTATUS(s) == 2}], 0, NULL) = 19232
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=19232, si_uid=0, si_status=2, si_utime=0, si_stime=0} ---
rt_sigreturn({mask=[]}) = 19232
wait4(-1, 0x7ffc1557c59c, WNOHANG, NULL) = -1 ECHILD (No child processes)
stat("/tmp/apt-key-gpghome.nBHDrgCJ0q/aptwarnings.log", 0x7ffc1557c4d0) = -1 ENOENT (No such file or directory)
faccessat(AT_FDCWD, "gpgconf", X_OK) = -1 ENOENT (No such file or directory)
faccessat(AT_FDCWD, "/usr/local/sbin/gpgconf", X_OK) = -1 ENOENT (No such file or directory)
faccessat(AT_FDCWD, "/usr/local/bin/gpgconf", X_OK) = -1 ENOENT (No such file or directory)
faccessat(AT_FDCWD, "/usr/sbin/gpgconf", X_OK) = -1 ENOENT (No such file or directory)
faccessat(AT_FDCWD, "/usr/bin/gpgconf", X_OK) = 0
openat(AT_FDCWD, "/dev/null", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
fcntl(1, F_DUPFD, 10) = 11
close(1) = 0
fcntl(11, F_SETFD, FD_CLOEXEC) = 0
dup2(3, 1) = 1
close(3) = 0
fcntl(2, F_DUPFD, 10) = 12
close(2) = 0
fcntl(12, F_SETFD, FD_CLOEXEC) = 0
dup2(1, 2) = 2
stat("/usr/local/sbin/gpgconf", 0x7ffc1557c660) = -1 ENOENT (No such file or directory)
stat("/usr/local/bin/gpgconf", 0x7ffc1557c660) = -1 ENOENT (No such file or directory)
stat("/usr/sbin/gpgconf", 0x7ffc1557c660) = -1 ENOENT (No such file or directory)
stat("/usr/bin/gpgconf", {st_mode=S_IFREG|0755, st_size=178848, ...}) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f1cd10ac850) = 19237
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 19237
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=19237, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
rt_sigreturn({mask=[]}) = 19237
dup2(11, 1) = 1
close(11) = 0
dup2(12, 2) = 2
close(12) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f1cd10ac850) = 19242
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 19242
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=19242, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
rt_sigreturn({mask=[]}) = 19242
wait4(-1, 0x7ffc1557c83c, WNOHANG, NULL) = -1 ECHILD (No child processes)
exit_group(2) = ?
+++ exited with 2 +++
我会非常感激您的帮助。如果我需要提供更多信息,我很乐意提供。谢谢。
答案1
我已经解决了这个问题。
apt-key adv
,基本上告诉 GnuPG 从服务器下载密钥。首先,我认为密钥不存在,因为通过密钥服务器网站上的搜索结果为负数。但当将其添加0x
到密钥前面时,就会找到它。在密钥服务器上未找到密钥或密钥服务器不可访问问题是已知的。
然后我直接打电话gpg
通过以下方式下载密钥:
gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
这也失败了,并显示相同的错误消息。然后我发现了一个Arch Linux BBS 主题,描述了同样的问题。他们的解决方案是修复文件/etc/resolve.conf
。事实上,这也帮助了我(显然我的systemd-resolved.service
失败了)。
如果错误消息更有帮助的话,那就容易多了。但是,好吧。我想这是我的错,因为我没有正确设置 DNS。