0

我通过 Nix(在Arch Linux上)安装了 Git 。

[gorre@uplink ~]$ uname -a
Linux uplink 4.16.9-1-ARCH #1 SMP PREEMPT Thu May 17 02:10:09 UTC 2018 x86_64 GNU/Linux
[gorre@uplink ~]$ nix-env -q
erlang-20.3.2
git-2.16.3
go-1.10.1
google-drive-ocamlfuse-0.6.25
nix-2.0.2

我将 SSH 配置文件保存在~/.ssh/config

[gorre@uplink ~]$ cat ~/.ssh/config 
# Bitbucket.org
Host bitbucket.org
#RSAAuthentication yes
IdentityFile ~/.ssh/bitbucket_id_rsa
IdentitiesOnly yes

我 100% 确定私钥/公钥集是正确的。我一直在 SmartGit 中使用它,但是当我尝试通过命令行使用 Git 时,我收到了这个错误:

[gorre@uplink erlang]$ git pull --rebase
sign_and_send_pubkey: signing failed: agent refused operation
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

有没有办法告诉 Git(通过 Nix 安装)引用我的~/.ssh/config文件?


作为证明,当我“指示”ssh-agent临时使用我的公钥时会发生这种情况(因此您可以确定我拥有正确的权利):

[gorre@uplink erlang]$ ssh-agent sh -c 'ssh-add ~/.ssh/bitbucket_id_rsa; git pull --rebase'
Enter passphrase for /home/gorre/.ssh/bitbucket_id_rsa: 
Identity added: /home/gorre/.ssh/bitbucket_id_rsa (/home/gorre/.ssh/bitbucket_id_rsa)
Already up to date.
Current branch master is up to date.

...在那之后,我可以自由飞行一段时间:

[gorre@uplink erlang_simple_cache]$ git pull --rebase
Already up to date.
Current branch master is up to date.
4

2 回答 2

2

我遇到了相同的错误消息(在 Debian 上),但原因不同。

问题是 OpenSSH 8.8 中的 RSA SHA-1 弃用: https ://www.openssh.com/txt/release-8.8 (“可能不兼容的更改”)。

通过生成和上传新的 ed25519 密钥来解决。

调试“权限被拒绝”错误ssh -v git@...没有结果,因为 /nix 中的 git 使用 /nix 中的 ssh,而不是系统 ssh。 GIT_TRACE=1 git ...输出显示了实际使用的 ssh 二进制文件的路径。

于 2022-02-07T10:46:47.440 回答
1

通常最好将它们作为 ssh 故障而不是 git 故障进行调试。用 诊断它们ssh -v -v git@bitbucket.org。您应该得到相同的错误,以及更多的诊断信息。但是我们已经有了我们需要的线索,sign_and_send_pubkey: signing failed: agent refused operation. 谷歌搜索我们发现这意味着ssh-agent无法访问该密钥

IdentityFile只说尝试哪个键,而不是尝试所有键。该密钥仍然必须可用。这就是它在你之后工作的原因ssh-add,它使你的 ssh 代理可以使用密钥。添加密钥通过ssh-add是正确的做法。

如果您每次登录时都必须记住添加密钥很烦人,那么您可以使用钥匙串来安全地存储您的 ssh 密钥阶段短语。然后下次登录时,您的钥匙串将ssh-add使用缓存的钥匙串为您运行。每个操作系统的钥匙串都不同。这是 ArchLinux 上的说明

于 2018-05-27T00:29:16.993 回答