git ssh 克隆不适用于 github
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11585636/
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
ssh clone not working with github
提问by sabari
I am new to Git and GitHub.
我是 Git 和 GitHub 的新手。
I created a new repository and tried to clone on my local machine.
我创建了一个新的存储库并尝试在我的本地机器上进行克隆。
It worked for https and git-readonly URLs. That is, the following worked fine:
它适用于 https 和 git-readonly URL。也就是说,以下工作正常:
git clone https://github.com/npsabari/testrepo.git
git clone git://github.com/npsabari/testrepo.git
git clone https://github.com/npsabari/testrepo.git
git clone git://github.com/npsabari/testrepo.git
But when I tried git clone [email protected]:npsabari/testrepo.git
, it didn't work. It gave the following error message:
但是当我尝试时git clone [email protected]:npsabari/testrepo.git
,它没有用。它给出了以下错误消息:
Cloning into 'testRepo'...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
And then I tried ssh [email protected]
, but I got the error:
然后我尝试了ssh [email protected]
,但我得到了错误:
"Permission denied (publickey)."
instead of the welcome message.
而不是欢迎信息。
What should I do to fix this? What is the reason for the error?
我该怎么做才能解决这个问题?错误的原因是什么?
回答by Mihai Maruseac
As per GitHub help, the error you're gettingis related to wrong SSH configuration. Please follow indications for setting up SSH for GitHuband check accordingly.
根据 GitHub帮助,您遇到的错误与错误的 SSH 配置有关。请按照指示为GitHub 设置 SSH并进行相应检查。
回答by Lusitanian
The reason for the error is that you don't have your public key (~/.ssh/id_rsa.pub) uploaded to GitHub. Add it to your account(you may do this through the web panel provided by github) and it will work.
错误的原因是您没有将您的公钥 (~/.ssh/id_rsa.pub) 上传到 GitHub。将其添加到您的帐户(您可以通过 github 提供的 Web 面板执行此操作),它将起作用。
回答by Frederik Struck-Sch?ning
I experienced this - only once ever - that the key generated by ssh-keygen
was broken. Checking the private and public key-files, they have the correct syntax, length, et.c.
我经历过这种情况 - 只有一次 - 生成的密钥ssh-keygen
被破坏了。检查私钥和公钥文件,它们具有正确的语法、长度等。
It. Just. Didn't. Work.
它。只是。没有。工作。
On the same machine, I re-generated a key-pair. This finally let me connect to github via ssh.
在同一台机器上,我重新生成了一个密钥对。这终于让我通过 ssh 连接到 github。
回答by Paritosh Singh
Actually first you should do generate ssh keys and then save them in your account.
实际上,您应该首先生成 ssh 密钥,然后将它们保存在您的帐户中。
See the following link for more details
请参阅以下链接了解更多详情
回答by Chetan Pangam
You can either follow the below document to add your key to ssh-agent
https://help.github.com/en/articles/connecting-to-github-with-ssh
您可以按照以下文档将您的密钥添加到ssh-agent
https://help.github.com/en/articles/connecting-to-github-with-ssh
or you can run the following command to execute it temporarily
或者您可以运行以下命令暂时执行它
ssh-agent bash -c 'ssh-add ~/.ssh/github_rsa; git clone git://github.com/npsabari/testrepo.git'
ssh-agent bash -c 'ssh-add ~/.ssh/github_rsa; git clone git://github.com/npsabari/testrepo.git'
回答by hexYeah
I would like to add that if you need to use sudo
, it could interfere as the SSH key is not bound to that user. You might want to edit the rights before using git
rather then after.
我想补充一点,如果您需要使用sudo
,它可能会干扰,因为 SSH 密钥未绑定到该用户。您可能希望在使用之前git
而不是之后编辑权限。
回答by surendrapanday
There are two ways to clone.1. SSH
2. HTTPS
In my case first one had given similar issue as you got, but then I tried using HTTPS
way by running following commands.git clone https://xyz
Before that run this command git remote -v
. This should show1. git-url(fetch)
2. git-url(push)
If you see these both upon running command, it tells you that you got push
right as well fetch
rights. After you have configured, and set proxy properly, if you still find problem, this solution I have explained should work. If your SSH public key and private key
are wrong then, you must fix that first before anything else.
克隆有两种方法。1. SSH
2. HTTPS
在我的情况下,第一个给出了与您类似的问题,但随后我尝试HTTPS
通过运行以下命令来使用way。git clone https://xyz
在此之前运行此命令git remote -v
。这应该显示1. git-url(fetch)
2. git-url(push)
如果您在运行命令时看到这两个,它告诉您您也获得了push
正确的fetch
权利。在您配置好并正确设置代理后,如果您仍然发现问题,我解释的这个解决方案应该可以工作。如果你SSH public key and private key
错了,你必须先解决这个问题,然后再做其他事情。