我用的是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没有密码,但仍然错误。


当前回答

我今天在尝试使用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字符,那么这可能是一个可能的原因。

其他回答

如果你有多个钥匙,你可能需要这样做 ssh-add private-keyfile

使用来自Github的ssh链接,但确保不要附加ssh,只需使用git hub上的ssh选项卡来克隆你的repo。

当我试图运行一个makefile时,我得到了类似的权限拒绝(publickey)错误。

作为上述SSH步骤的替代方法,您可以安装本地GitHub for Mac应用程序。

点击下载GitHub for Mac从- https://help.github.com/articles/set-up-git#platform-mac

一旦你用你的git hub帐户完成了设置(我也安装了git hub命令行工具,但不确定是否需要这一步),然后我收到了一封电子邮件-

[GitHub]一个新的公钥已添加到您的帐户

我的错误被纠正了。

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

伙计们我是这么干的

Open terminal and go to user [See attached image] Open .ssh folder and make sure it doesn't have any file like id_rsa or id_rsa.pub otherwise sometimes it wont properly rewrite files git --version [Check for git installation and version] git config --global user.email "your email id" git config --global user.name "your name" git config --list [make sure you have set your name & email] cd ~/.ssh ssh-keygen, it prompts for saving file, allow it cat ~/.ssh/id_rsa.pub [Access your public key & copy the key to gerrit settings]

注意:你不应该在Git中使用sudo命令。如果您有非常好的理由必须使用sudo,那么请确保您在每个命令中都使用它(此时使用su作为根来获取shell可能更好)。如果您不使用sudo生成SSH密钥,然后尝试使用sudo git push之类的命令,那么您将不会使用您生成的相同密钥