git push:权限被拒绝(公钥)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19660744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git push: permission denied (public key)
提问by Wyguf Seak
I'm trying to push a file to a git repo of a friend but errors on public key.
我正在尝试将文件推送到朋友的 git 存储库,但公钥出错。
git push origin testbranch
Permission denied (publickey).
fatal: Could not read from remote repository.
Where and how do we define public / private keys?
我们在哪里以及如何定义公钥/私钥?
git remote -v
returns:
git remote -v
返回:
origin [email protected]:Sesamzaad/NET.git (fetch)
origin [email protected]:Sesamzaad/NET.git (push)
Any help is appreciated.
任何帮助表示赞赏。
回答by user3445140
I was facing same problem, here is what I did that worked for me.
我遇到了同样的问题,这就是我所做的对我有用的事情。
Use ssh instead of http. Remove origin if its http.
使用 ssh 而不是 http。如果是 http,则删除原点。
git remote rm origin
Add ssh url
添加 ssh 网址
git remote add origin [email protected]:<username>/<repo>.git
Generate ssh key inside .ssh/ folder. It will ask for path and passphrase where you can just press enter and proceed.
在 .ssh/ 文件夹中生成 ssh 密钥。它会询问路径和密码,您只需按 Enter 键并继续。
cd ~/.ssh
ssh-keygen
Copy the key. You can view your key using. If you hadn't specified a different path then this is the default one.
复制密钥。您可以使用查看您的密钥。如果您没有指定不同的路径,那么这是默认路径。
cat ~/.ssh/id_rsa.pub
Add this key to your github account. Next do
将此密钥添加到您的 github 帐户。下一步做
ssh -T [email protected]
You will get a welcome message in your console.
您将在控制台中收到欢迎消息。
cd into to your project folder. git push -u origin master
now works!
cd 到您的项目文件夹。git push -u origin master
现在有效!
回答by steel
I just had to deal with this issue. @user3445140's answer helped me, but was much more than I needed to do.
我只是不得不处理这个问题。@ user3445140 的回答对我有帮助,但比我需要做的要多得多。
- Get your public SSH key with
cat ~/.ssh/id_rsa.pub
- Copy the key, including the "ssh-rsa" but excluding your computer name at the end
- Go to https://github.com/settings/ssh
- Add your SSH key
- 获取您的公共 SSH 密钥
cat ~/.ssh/id_rsa.pub
- 复制密钥,包括“ssh-rsa”,但最后不包括您的计算机名称
- 转到https://github.com/settings/ssh
- 添加您的 SSH 密钥
回答by Cloud13th
This worked for me.
这对我有用。
first of all, remove current remote :
首先,删除当前遥控器:
git remote rm origin
second, add remote through HTTPS but git@xxx :
其次,通过 HTTPS 添加远程但 git@xxx :
git remote add origin https://github.com/Sesamzaad/NET.git
then push has worked for me :
然后推送对我有用:
git push origin master
回答by vignesh787
I am running Ubuntu 16.04
我正在运行 Ubuntu 16.04
Removing the remote origin using
使用删除远程源
git remote rm origin
setting the http url using
使用设置http url
git remote add origin https://github.com/<<Entire Path of the new Repo>>
git push origin master
Above steps successfully added code to repo.
以上步骤成功地将代码添加到 repo。
回答by Bennet G.
I fixed it by re-adding the key to my ssh-agent.
我通过将密钥重新添加到我的 ssh-agent 来修复它。
with the following command:
使用以下命令:
ssh-add ~/.ssh/path_to_private_key_you_generated
ssh-add ~/.ssh/path_to_private_key_you_generated
For some reasons it was gone.
由于某些原因它消失了。
回答by vsahu
None of the above solutions worked for me. For context, I'm running ubuntu, and I had already gone through the ssh-key setup documentation. The fix for me was to run ssh-add
in the terminal. This fixed the issue.
以上解决方案都不适合我。对于上下文,我正在运行 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
回答by dberm22
This worked for me. Simplest solution by far.
这对我有用。迄今为止最简单的解决方案。
If you are using GitHub for Windows and getting this error, the problem might be that you are trying to run the command in the wrong shell or mode. If you are trying to do git push origin master
in the regular command promptor PowerShell, this is the problem.
如果您使用 GitHub for Windows 并收到此错误,则问题可能是您尝试在错误的 shell 或模式下运行命令。如果您尝试git push origin master
在常规命令提示符或PowerShell中执行此操作,这就是问题所在。
You need to do it in a git shell. Simply open Github for Windows, right click, and select "Open Shell Here". It looks like a regular PowerShell window, but it's not, which makes it really confusing for newbies to git, like myself.
您需要在git shell 中执行此操作。只需打开 Windows 版 Github,右键单击,然后选择“在此处打开 Shell”。它看起来像一个普通的 PowerShell 窗口,但它不是,这让像我这样的新手对 git 来说真的很困惑。
I hope others find this useful.
我希望其他人觉得这很有用。
回答by Walter B
You probably have to add your public key to github. https://help.github.com/articles/generating-ssh-keys
您可能必须将您的公钥添加到 github。https://help.github.com/articles/generating-ssh-keys
Check this thread: GitHub: Permission denied (publickey). fatal: The remote end hung up unexpectedly
回答by antikytheraton
The documentation from Github is really explanatory.
Github 的文档非常有说明性。
https://help.github.com/en/articles/adding-a-new-ssh-key-to-your-github-accounthttps://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
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
I think you must do the lasts steps from the guide to proper configure your keys
我认为您必须执行指南中的最后一步才能正确配置您的密钥
$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/id_rsa
回答by Sohaib Anwaar
Solution : you have to add you ssh key in your git-hub profile. Follow steps to solve this problem
解决方案:您必须在 git-hub 配置文件中添加 ssh 密钥。按照步骤解决这个问题
- Right Click Folder you want to push in git
- Select git-bash here problem
- Write command ssh-keygen by this command your key is generated
- Copy the key from cmd or go to (C:/User/your_user/.ssh/)
- open id.rsa with notepad.
- Copy your key
- Now go to your git-hub profile
- Go to settings
- select SSH and Gpg keys
- select New ssh keyoption
- add window-keyin the title
- Paste your key in the description part below title field
- Save
- 右键单击要在 git 中推送的文件夹
- 在这里选择 git-bash 问题
- 通过此命令写入命令 ssh-keygen 您的密钥已生成
- 从 cmd 复制密钥或转到 (C:/User/your_user/.ssh/)
- 用记事本打开 id.rsa。
- 复制您的密钥
- 现在转到您的 git-hub 个人资料
- 前往设置
- 选择SSH 和 Gpg 密钥
- 选择新建 ssh 密钥选项
- 在标题中添加窗口键
- 将您的密钥粘贴到标题字段下方的描述部分
- 节省
Now you are ready to push your folder
现在您已准备好推送您的文件夹
- Now go to folder you want to upload
- right click on the folder
- Select git bash here
- git init
- git add README.md
- git commit -m "first commit"
- git remote add origin https://github.com//
- git push -u origin master
- 现在转到您要上传的文件夹
- 右键单击文件夹
- 在这里选择 git bash
- git初始化
- git 添加 README.md
- git commit -m "第一次提交"
- 远程Git添加初始https://github.com//
- git push -u origin master
Hope this will be Helpful for you
希望这对你有帮助