Github SSH 访问 : Permission denied (publickey)

标签 git github git-remote

我最近通过 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并使用它。

Running Git through Cygwin from Windows也可能有用。

关于Github SSH 访问 : Permission denied (publickey),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50556966/

相关文章:

git - 如何在不通过我的本地计算机抽取所有内容的情况下将 Github 上的一个分支更新到上游版本?

git - 在与 main 相同的提交上分离 HEAD?

git - "fatal: HttpRequestException encountered."GitHub/Bitbucket 存储库因放弃 TLS-1.0 支持而出错

git - BitBucket - 如何从服务器检索所有存储库 url

git - 如何使用命令行将分支推送到gitlab

git - 为什么 "git rebase"在阶段和工作副本中留下相反的修改集?

git - 在未更新的母版上 merge 分支

git - 如何绕过 : remote: GitLab: Author <non-member-email-here> is not a member of team?

git - 删除本地分支的危急情况

基于 Git 的网站部署工作流程