我用的是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密钥与错误的电子邮件。我可以使用ssh连接,但不能使用git。解决方案是使用我的github帐户的主要电子邮件地址重新生成密钥。

其他回答

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

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

$ cd ~
$ cd .ssh
$ chmod 400 id_rsa

Windows上的另一种可能性,在这些答案中都没有涉及,git或github文档中也没有涉及故障排除:

Git使用的openssh可执行文件可能与您认为的不同。

当我试图从github和ssh.dev.azure.com克隆或拉时,我收到了权限拒绝(公钥)错误,我遵循了所有的说明,并验证我的SSH密钥被正确设置(从SSH的立场)使用SSH -vT git@github.com和SSH -vT git@ssh.dev.azure.com。并且仍然得到这些错误:

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

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

我最终发现问题在于Git for Windows和Windows都有自己的openssh版本。这里有文档:https://github.com/desktop/desktop/issues/5641

我依赖于Windows的ssh-agent服务来存储我的ssh密钥密码,所以git(使用它的单独版本的openssh)无法读取我的私钥。我认为这是一个错误,这个错误信息被使用-它是误导性的。

解决方案是:

git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"

或者在~/.gitconfig中:

[core]
    sshCommand = 'C:\\Windows\\System32\\OpenSSH\\ssh.exe'

也许git很快就会修复这个问题,但这已经是我第二次在这个问题上浪费时间了。

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

这些是我在windows 10中遵循的步骤

打开Git Bash。 生成公钥: ssh-keygen -t rsa -b 4096 -C "youremailaddress@xyz.com" 复制生成的键到剪贴板(像CTRL+C一样工作) 剪辑< ~/.ssh/id_rsa.pub 浏览器,进入Github => Profile=> Settings => SSH和GPG Key => Add Key 提供键名和粘贴剪贴板(CTRL+V)。 最后,测试您的连接(Git bash) ssh -T git@github.com

谢谢!