1

我为 Windows 和 Powershell 7.1 安装了 Git。当我尝试使用 ssh 密钥从 git bash 克隆存储库时,它运行良好。但是,当我尝试从 Powershell 7.1 执行类似操作时,我遇到了致命错误:无法从远程存储库中读取错误。

遵循的步骤

1. PS> Start-Service ssh-agent
2. PS> ssh-add D:\Keys\.ssh\my_private_key (I get identity added message)
3. PS> git clone git@github.com:my-username/my-repo.git

错误信息

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
4

1 回答 1

2

这意味着 ssh,在那个 Powershell 会话中,正在尝试寻找 SSH 密钥%USERPROFILE%而不是D:\Keys

如果您有一个~/.ssh/config文件可以指定正确的私钥用于Host github.com.
并检查在所述会话中解决了什么~(即)。 if 不应与 Powershell 会话中的默认 HOME 相同,其中 git 默认为echo $HOMEgit bash
%USERPROFILE%

于 2021-01-04T00:57:00.100 回答