我用的是Mac雪豹,刚刚安装了git。

我只是试了

git clone git@thechaw.com:cakebook.git

但这给了我这个错误:

Initialized empty Git repository in `/Users/username/Documents/cakebook/.git/`
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

我错过了什么? 我也试过做ssh-keygen没有密码,但仍然错误。


当前回答

这对我来说很管用:

ssh-add ~/.ssh/id_rsa

其他回答

如果用户未生成之前设置的ssh公私钥对

此信息在聊天上工作,但可以应用于所有其他支持SSH pubkey身份验证的git存储库。(参见[gitolite][1], gitlab或github。)

首先设置您自己的公钥/私钥对集。这 可以使用DSA或RSA,所以基本上你设置的任何密钥都可以工作。 在大多数系统上,您可以使用ssh-keygen。

First you'll want to cd into your .ssh directory. Open up the terminal and run: cd ~/.ssh && ssh-keygen Next you need to copy this to your clipboard. On OS X run: cat id_rsa.pub | pbcopy On Linux run: cat id_rsa.pub | xclip On Windows (via Cygwin/Git Bash) run: cat id_rsa.pub | clip On Windows (Powershell) run: Get-Content id_rsa.pub | Set-Clipboard (Thx to @orion elenzil) Add your key to your account via the website. Finally setup your .gitconfig. git config --global user.name "bob" git config --global user.email bob@... (don't forget to restart your command line to make sure the config is reloaded) That's it you should be good to clone and checkout.

更多信息请访问https://help.github.com/articles/generating-ssh-keys(感谢@Lee Whitney) [1]: https://github.com/sitaramc/gitolite

-

如果用户已经生成了之前设置的ssh公私钥对

检查哪个密钥已被授权在您的github或gitlab帐户设置 确定必须从本地计算机关联哪个相应的私钥

Eval $(ssh agent -s)

定义键的位置

ssh-add ~ / . ssh / id_rsa

我刚刚在设置我当前的项目时遇到了这个问题,上面的解决方案都不起作用。所以我试着用命令ssh -vT git@github.com查看调试列表上到底发生了什么。我注意到我的私钥文件名不在列表中。因此,将私钥文件名重命名为'id_rsa'就可以了。希望这能有所帮助。

这就是我如何最终能够推动git


对我来说,我一直在得到

git@github.com: Permission denied 
fatal: Could not read from remote 

Please make sure you have the correct access rights
and the repository exists.

所以经过几个小时的研究,我发现在生成您的ssh密钥并使您的windows代理识别您的密钥后,我做的最后一件事来解决我的问题是更新ssh密钥在git回购的项目。

你可以登录到你的git hub账户,然后进入你想要推送的repo,然后在设置中寻找安全性,在那里你可以添加ssh密钥。对于我来说,密钥存储在.ssh/id_ed123939.pub中

对我来说,实际的问题是使用文本编辑器复制SSH公钥到剪贴板

如果按照docs.github.com,在notepad++等文本编辑器中打开。pub文件复制SSH公钥,那么就有麻烦了。

而不是使用

猫~ / . ssh / id_ * * *。Pub |剪辑

复制命令

我今天在尝试使用git bash在windows中设置一个现有的存储库时遇到了这个问题。问题出现在输入以下内容时:

git clone myreposshurl

在gitbash中,ctrl+c和ctrl+v不起作用。在尝试粘贴存储库url时,我按了ctrl+v,这引入了一些不需要的字符。当我尝试并成功克隆另一个存储库时,终于发现并解决了这个问题。花了一个半小时才发现这个愚蠢的错误。

\302\226git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

如果你看到像上面这样的\302字符,那么这可能是一个可能的原因。