我用的是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密钥生成程序,而不是一些过时的博客

https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

在这里你可以看到键是通过以下方式生成的:

ssh-keygen -t ed25519 -C "your_email@example.com"

所以算法是ed25519而不是rsa或者别的什么。

其他回答

这对我很有效

ssh -i [your id_rsa path] -T github@github.com

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

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

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

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

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

我的错误被纠正了。

我也犯了同样的错误。

问题是,当将公钥复制到BitBucket(在我的情况下)时,在末尾复制/粘贴了一个不可见的换行符。

因此,在复制公钥时,首先将其复制到记事本,删除末尾的空行,复制并粘贴。

更广泛的故障排除,甚至自动修复可以完成:

ssh -vT git@github.com

或者,根据以下意见,我们可以发出:

ssh -vT git@gitlab.com

或者用你的组织正在运行的Git实例替换gitlab/github。

来源:https://help.github.com/articles/error-permission-denied-publickey/

在我的情况下,我重新安装了ubuntu,用户名从以前的改变。在这种情况下,生成的ssh密钥也与之前的密钥不同。

这个问题通过在存储库中复制当前的ssh公钥来解决。密钥将在用户的/home/.ssh/id_rsa.pub中可用