【问题标题】:git@github.com: Permission denied (publickey)git@github.com:权限被拒绝(公钥)
【发布时间】:2020-01-04 04:13:40
【问题描述】:

我创建了一个新的远程存储库,并尝试使用git push -u origin master 命令将我的本地文件推送到新的存储库中,这是我在add 它和commit 它之后的第一次。但是,它会弹出这个git@github.com: Permission denied (publickey). fatal: Could not read from remote repository.。我该如何解决这个致命错误?

我试过了
How to solve Permission denied (publickey) error when using Git? 这个链接中的问题似乎是第一次使用 git 时发生的。我已经使用我的 git 一段时间了,我还需要遵循这个解决方案吗?谁能给我一个更具体的解决方案?

这是我遇到的致命错误

C:\Users\ASUS\Desktop\React-Practice App\my-app>git status
On branch master
nothing to commit, working tree clean

C:\Users\ASUS\Desktop\React-Practice App\my-app>git push -u origin master
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.

【问题讨论】:

标签: git github git-push


【解决方案1】:

您正在通过 SSH 访问 GitHub。首先生成一个SSH密钥对;然后将公钥添加到 GitHub。

生成密钥对,github偏爱“Ed25519算法”

ssh-keygen -t ed25519 -C "your_email@example.com"

它仍然允许将 rsa 用于不支持 Ed25519 的系统

ssh-keygen -t rsa -b 4096 -C “youremail@example.com”

https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agenthttps://help.github.com/en/articles/adding-a-new-ssh-key-to-your-github-account 上查看更多信息

【讨论】:

  • 我已经使用这个命令ls -al ~/.ssh 来检查我是否有一个现有的 ssh 密钥。结果是我已经有了。因此,如果我已经有一个,为什么还要生成一个新的?
  • 导航到 github 配置文件 > 设置 > SSH 和 GPG 密钥 > 新的 SSH 密钥。在文本字段中粘贴 ~/.ssh/id_rsa.pub 文件的内容。在答案的第二个链接中查看更多信息。
  • 我已经有一个 ssh 密钥,并且它是加密的。所以我需要先通过像这样添加它(在 Mac 上)来解锁它:ssh-add ~/.ssh/id_rsa,其中id_rsa 是你的 ssh 的密钥。然后输入我的加密密码。
  • Ubuntu 上运行 ssh-add id_rsa 后我收到错误 无法打开与您的身份验证代理的连接 如果您遇到此问题。运行 1) exec ssh-agent bash 2) ssh-add <your_key> .) video
【解决方案2】:

即使在 github 上添加 ssh 密钥后也遇到同样的问题。

通过运行此命令修复它

ssh -vT git@github.com

【讨论】:

  • 非常感谢!它显示了错误日志,并发现 git 在尝试进行身份验证时使用了特定的路径 (~/.ssh) 和文件名 (id_)。我不应该重命名它。
  • 谢谢,这解决了我今天在 Github 上遇到的问题。
【解决方案3】:

我遇到了这个问题,因为我像 @Mon 那样为我的密钥使用了非标准位置。就我而言,我没有使用默认文件名,因为我的系统上有多个密钥。所以不能简单地通过移动或重命名来解决它。

解决方案是编辑或创建 ~/.ssh/configconfigConfiguring the Location of Identity Keys 的 OpenSSH 文档)以包含以下内容:

Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/github-key
  • 不要不要编辑第 3 行以反映您自己的用户名。用户名应为git(请参阅github docs)。

  • 编辑第 4 行以反映密钥的位置。

如果您已经有一个config 文件,那么在四处寻找之前看看里面有什么是值得的。在编辑之前制作副本永远不会有什么坏处。

以上假设您已经创建了密钥,并将其放在 github 上,您实际上确实拥有权限,其他一切正常,但仍然遇到错误。

【讨论】:

  • 在推送失败后我尝试了许多解决方案,但这对我也有用,在使用 putty gen 将我的密钥转换为新的开放 ssh 格式后
【解决方案4】:

当我遇到这个问题时,我的 git remote origin url 中出现了拼写错误。也许您可以仔细检查所有内容是否拼写正确,而无需任何额外的意外击键?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-18
    • 1970-01-01
    • 2013-11-08
    • 2020-11-03
    • 1970-01-01
    • 2021-12-06
    • 2016-11-01
    相关资源
    最近更新 更多