我最近通过 Cygwin 在 Win10 上设置了一个 git 存储库,现在我正试图让它跟踪 github 上的一个远程存储库。
问题是,在像这样添加一个 Remote 之后:
git remote add github-remote git@github.com:username/github-remote.git
我无法以任何可能的方式访问它(推送、获取、通过“显示”显示附加信息)。我得到的是:
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
虽然我知道这个话题已经被讨论了很多,但我找到的解决方案都没有实际帮助。这就是为什么我决定发布另一个问题。
这是我一步一步做的:
1) 生成 pub-priv key 对:
ssh-keygen -t rsa -b 4096 -C "mymail@ex.com"
尝试同时使用 - id_rsa 文件的默认目录和自定义目录。相同的结果。
2) 运行 ssh 代理(或者准确地说,检查它是否正在运行):
eval $(ssh-agent -s)
3) 将 key 添加到代理中
ssh-add ~/.ssh/id_rsa
4) 将 id_rsa.pub 复制到 github
5) 检查连接设置是否正确
ssh -T git@github.com
... 有希望的结果
You've successfully authenticated, but GitHub does not provide shell access.
据我了解,此错误可能是由于 git 的地址未包含在/.ssh/known_hosts 文件中所致。事情是(据我所知)它是自动插入的,例如使用'ssh -T'所以我也怀疑是这种情况。尽管也尝试过:
ssh-keyscan -t rsa github.com | ssh-keygen -lf -
另一个可能的问题可能是我的私钥访问范围对用户来说太广泛了,但我也检查过了。
综上所述,我不知道如何解决这个问题,所以我将不胜感激任何帮助。提前谢谢你。
最佳答案
As for git, I downloaded the .exe from git-scm.com/download/win. SSH on the other hand I had to install as a Cygwin's package, and it's Cygwin's mintty in which I run all of the commands...
混合 Cygwin 和 Git For Windows可能是问题所在。虽然我确信有一种方法可以让它们发挥作用,但最简单的方法是坚持其中一个。
Windows 版 Git 带有自己的“Git Bash”外壳,我相信还有 ssh。用那个。
或者,如果您想坚持使用 Cygwin,get Git from from Cygwin并使用它。
关于Github SSH 访问 : Permission denied (publickey),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50556966/