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


当前回答

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

命令1:

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

eval "$(ssh-agent -s)"

命令2:

将SSH密钥添加到SSH -agent:

ssh-add ~/.ssh/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中

我有一个轻微不同的情况,我登录到一个远程服务器,并在服务器上使用git,当我运行任何git命令时,我得到了相同的消息

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

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

ForwardAgent no 

to

ForwardAgent yes

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

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

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

我想这是个bug。

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

我删除了node_modules/ package-lock。Json和yarn。锁文件。再次运行npm i。这为我解决了问题。

在MAC中,进入终端

1)使用命令- cd ~进入主目录

2) cd .ssh && ssh-keygen(默认情况下,双击输入/返回键)

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/username/.ssh/id_rsa):      
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/usernmae/.ssh/id_rsa.

3)之后,做“ls”。您将找到id_rsa。酒吧文件。

4)复制id_rsa. conf文件中的内容。Pub文件(使用cat命令读取- cat id_rsa.pub)

5)导航到BitBucket或任何支持SSH密钥的版本工具。使用“添加键选项”粘贴内容

就是这样。试着现在就做出承诺和努力。