GIT推送:权限被拒绝(公钥)

时间:2013-10-29 14:15:55

标签: git permissions key public denied

GIT:我正在尝试将文件推送到朋友的回购,但公钥上有错误。

git push origin testbranch
Permission denied (publickey).
fatal: Could not read from remote repository.

我们在哪里以及如何定义公钥/私钥?

git remote -v返回:

origin  git@github.com:Sesamzaad/NET.git (fetch)
origin  git@github.com:Sesamzaad/NET.git (push)

感谢任何帮助。

17 个答案:

答案 0 :(得分:73)

我遇到了同样的问题,这就是我所做的对我有用的事情。

使用ssh而不是http。如果是http。

,请删除原点
git remote rm origin

添加ssh网址

git remote add origin git@github.com:<username>/<repo>.git

在.ssh /文件夹中生成ssh密钥。它会询问路径和密码,您只需按Enter键即可继续。

cd ~/.ssh
ssh-keygen

复制密钥。您可以使用查看密钥。如果您没有指定其他路径,那么这是默认路径。

cat ~/.ssh/id_rsa.pub

将此密钥添加到您的github帐户。接下来做

ssh -T git@github.com

您将在控制台中收到欢迎信息。

进入您的项目文件夹。 git push -u origin master现在有效!

答案 1 :(得分:18)

我只需处理这个问题。 @ user3445140的答案对我有所帮助,但远远超过了我的需要。

1. cat ~/.ssh/id_rsa.pub
2. copy the key, including the "ssh-rsa" but *excluding your computer name at the end*
3. Go to: https://github.com/settings/ssh
4. Add your SSH key

答案 2 :(得分:11)

这对我有用。

首先,删除当前的远程:

git remote rm origin

第二,通过HTTPS添加远程,但是git @ xxx:

git remote add origin https://github.com/Sesamzaad/NET.git

然后推送对我有用:

git push origin master

答案 3 :(得分:7)

我正在运行Ubuntu 16.04

使用

删除远程原点
git remote rm origin

使用

设置http网址
git remote add origin https://github.com/<<Entire Path of the new Repo>>

git push origin master

以上步骤成功将代码添加到repo。

答案 4 :(得分:5)

以上解决方案均不适合我。对于上下文,我正在运行ubuntu,我已经完成了ssh-key安装文档。对我来说,修复是在终端中运行ssh-add。这解决了这个问题。

来源:http://baptiste-wicht.com/posts/2010/07/tip-how-to-solve-agent-admitted-failure-to-sign-using-the-key-error.html

答案 5 :(得分:4)

我通过读取我的ssh-agent的密钥来修复它。由于某些原因,它已经消失了。

答案 6 :(得分:1)

这对我有用。迄今为止最简单的解决方案。

如果您使用GitHub for Windows并收到此错误,则问题可能是您尝试在错误的shell或模式下运行该命令。如果您尝试在常规命令提示符 PowerShell 中执行git push origin master,则会出现问题。

您需要在 git shell 中执行此操作。只需打开Github for Windows,右键单击,然后选择“在这里打开Shell”。它看起来像一个常规的PowerShell窗口,但事实并非如此,这让像我这样的git的新手真的很困惑。

我希望其他人觉得这很有用。

答案 7 :(得分:1)

答案 8 :(得分:1)

如果遇到403错误,请采取以下解决方法:

 The requested URL returned error: 403

在您的帐户中注册了另一个帐户后,您需要从Windows中删除github凭据

control panel > user accounts > credential manager > Windows credentials > Generic credentials

then remove the Github keys

答案 9 :(得分:0)

要部署到朋友的仓库,您需要将公钥添加到存储库的部署密钥。

转到存储库,转到部署密钥,然后将id_rsa.pub(或您的任何名称)添加到“部署密钥”。

我认为将密钥添加到您自己的帐户只允许您写入您的帐户创建的存储库。如果它是由组织创建的,则需要将密钥添加到repo的部署密钥。

https://developer.github.com/v3/guides/managing-deploy-keys/

答案 10 :(得分:0)

如果您已将公钥添加到GITHUB服务器,则可以尝试其他解决方案。

在我的情况下,GIT PUSH从RUBYMINE内部失败,但是从终端窗口执行此操作解决了问题。

有关更多解决方案,请访问此页面 的 https://github.com/gitlabhq/gitlabhq/issues/4730

答案 11 :(得分:0)

我也遇到了同样的问题。请转到好友的回购设置并添加新的协作者,以将您添加为协作者。

您将收到一封邀请电子邮件,接受它即可。 只要确保您已添加正确的遥控器即可。

答案 12 :(得分:0)

在Windows上使用Ubuntu Bash时发生此错误。

我切换到标准Windows cmd提示符,但没有错误。

这是一种解决方法,因为这意味着如果要使用ubuntu,则可能需要在ubuntu环境中加载ssh私钥。

答案 13 :(得分:0)

您需要将项目派生到您自己的用户存储库中。
然后add origin

git remote add upstream your-ssh-here <br>
git fetch upstream <br>
git branch --set-upstream-to=upstream/master master

答案 14 :(得分:0)

Github的文档确实具有解释性。

https://help.github.com/en/articles/adding-a-new-ssh-key-to-your-github-account https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

我认为您必须按照指南进行最后操作,以正确配置密钥

$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/id_rsa

答案 15 :(得分:0)

解决方案: 您必须在git-hub配置文件中添加ssh键。按照步骤解决此问题

  1. 您要在git中推送的右键文件夹
  2. 在这里选择git-bash问题
  3. 通过此命令编写ssh-keygen命令,即可生成密钥
  4. 从cmd复制密钥或转到(C:/User/your_user/.ssh /)
  5. 使用记事本打开id.rsa。
  6. 复制密钥
  7. 现在转到您的git-hub个人资料
  8. 转到设置
  9. 选择 SSH和Gpg密钥
  10. 选择新的ssh密钥选项
  11. 在标题中添加窗口键
  12. 将密钥粘贴到标题字段下方的描述部分
  13. 保存

现在您可以开始推送文件夹了

  1. 现在转到您要上传的文件夹
  2. 右键单击文件夹
  3. 在此处选择git bash
  4. git init
  5. git添加README.md
  6. git commit -m“首次提交”
  7. git remote add origin https://github.com/ /
  8. git push -u原始主机

希望这对您有帮助

答案 16 :(得分:0)

如果你的 git 账户中已经生成了 ssh 密钥,那么只需执行以下操作-

ssh-add -k ~/.ssh/id_rsa