我用的是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,当我运行任何git命令时,我得到了相同的消息

   Permission denied (publickey).
   fatal: The remote end hung up unexpectedly

我是通过修改Mac上的/etc/ssh_config文件来解决这个问题的。 从

ForwardAgent no 

to

ForwardAgent yes

其他回答

我得到这个错误,因为我生成的ssh密钥与错误的电子邮件。我可以使用ssh连接,但不能使用git。解决方案是使用我的github帐户的主要电子邮件地址重新生成密钥。

伙计们我是这么干的

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之类的命令,那么您将不会使用您生成的相同密钥

github帮助链接帮助我解决了这个问题。看起来ssh密钥没有添加到ssh-agent。这就是我最后做的事。

命令1:

确保ssh-agent已启用。在后台启动ssh-agent:

eval "$(ssh-agent -s)"

命令2:

将SSH密钥添加到SSH -agent:

ssh-add ~/.ssh/id_rsa

在我的MAC中,我解决了这个问题:

cp ~/.ssh/github_rsa ~/.ssh/id_rsa

出于某种原因,我的git停止在github_rsa文件中寻找私钥。这发生在一次特定的回购中。我的意思是在其他存储库中git保持正常工作。

我想这是个bug。

我可以在运行ssh -vT git@github.com时发现这种行为

基本的GIT指令没有引用SSH密钥之类的东西。沿着上面的一些链接,我发现了一个git帮助页面,它一步一步地解释了如何在各种操作系统上做到这一点(链接将检测您的操作系统并相应地重定向):

http://help.github.com/set-up-git-redirect/

它介绍了GITHub所需的所有内容,并给出了详细的解释,例如“为什么在创建RSA密钥时添加密码短语”。我想我应该把它贴出来,说不定能帮助到别人……