【问题标题】:Git push origin Permission to * denied fatal: Could not read from remote repositoryGit push origin Permission to * denied fatal: 无法从远程存储库读取
【发布时间】:2018-06-22 21:38:30
【问题描述】:

所以我将我的公共 ssh 密钥添加到了 git 存储库中。我已将私钥添加到我的 /c/Users/totty/.ssh/ 中。

当我运行ssh -vT git@github.com 时,它显示Hi X! You've successfully authenticated, but GitHub does not provide shell access.

当我运行git push origin 时,我得到Permission to * denied fatal: Could not read from remote repository

这个 github 有什么问题?我无法从 cmd、git 扩展中推送。但它可以从 Windows 的 github 运行...

删除我的 ssh 密钥并运行 ssh -vT git@github.com 后,我得到 debug1: No more authentication methods to try.


还有一件奇怪的事情......如果你看一下圈出来的文字,那不是我的用户名或电子邮件。我什至检查了我的 git 配置并且无处可去。来自哪里?我的意思是gs11118

【问题讨论】:

    标签: git github


    【解决方案1】:

    首先,用户名/电子邮件(您使用git config user.name / user.email 设置的那个)与 GitHub 凭据(用户 GitHub 帐户名)无关

    其次,确保您的 git push 实际使用的是 SSH URL:

    cd /path/to/my/local/repo
    git remote -v
    

    如果您看到以 https://... 开头的 URL,那么 ssh -T git@github.com 是否正确识别您并不重要:Git 不会将其用作凭据。它将使用存储在Windows Credentials Manager 中的内容。

    【讨论】:

      【解决方案2】:

      您可以推送到不属于您或您拥有的仓库,该仓库是从其他人那里克隆的。

      仓库的 SSH 格式的 URL(可以用git remote -v 显示)是这样的:

      origin  git@github.com:username/repo.git(fetch)
      origin  git@github.com:username/repo.git(push)
      

      或HTTPS格式:

      origin  https://github.com/username/repo.git(fetch)
      origin  https://github.com/username/repo.git(push)
      

      在您的存储库中,您可能会发现username 不是您的,也不是您的组织或合作者的。然后,如果你想推送它,你可以来到原始存储库(https://github.com/username/repo),到 fork 那个 repo 到你的 GitHub 帐户(作为问题的github 标签),然后使用git remote set-url origin 命令重写本地 repo 的远程 URL。

      之后,您可以将其推送到您拥有的遥控器,作为其他人的分叉。 编辑:如果你使用 HTTPS 方式,你可以看看Git Credentials

      或者,如果源存储库是您负责进行开发的地方,您可以请求组织或合作者将您添加为合作者。

      EDIT2:感谢@VonC的评论(谈话?),您可以查看文件~/.ssh/config,由于您提供的图像可能是C:\Users\totty\.ssh\config,以查找是否this repo 有一个指定的密钥,IdentityFile参考Specify an SSH key for git push for a given domain

      【讨论】:

      • 否:远程仓库无关紧要。重要的是(在 OP 图片中的红色圆圈中)是 GitHub 用于对该远程存储库进行身份验证的用户名(拥有与否):该用户名 不是 预期的用户名。我的回答表明在哪里可以找到那个意外的用户名。一旦使用的用户名是正确的,那么只有这样:你的答案才会适用。
      • @VonC 我尝试使用 SSH 方式推送到其他存储库,错误是'Permission to /.git denied to .',使用 HTTPS 方式会有更多错误'致命:无法访问'github.com/<other>/<repo>.git':请求的URL返回错误:403'。但是,OP 没有收到 HTTPS 的错误消息,也不知道“我”(gs11118)是谁。 this repo 是否有可能错误地使用了 gs11118 的 SSH 密钥?
      • 可能是的:这实际上取决于用于“来源”的实际 URL。关于 ssh,它是远程 URL)可以引用 ~/.ssh/config 中的条目,这将引用错误的私钥。
      • @VonC 谢谢。我添加了一些看起来相关的答案。
      • 这不是一个实际的答案,回答的人似乎并不完全理解问题所在。
      猜你喜欢
      • 2013-04-13
      • 2014-05-04
      • 1970-01-01
      • 1970-01-01
      • 2015-03-11
      • 2020-01-20
      • 1970-01-01
      • 2019-10-24
      • 2018-12-10
      相关资源
      最近更新 更多