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


当前回答

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 -vT git@github.com

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

ssh -vT git@gitlab.com

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

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

在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密钥的版本工具。使用“添加键选项”粘贴内容

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

您可以在终端中执行以下操作:

cd ~ / . ssh ssh-keygen -o -t rsa -C "your@email.com" 当提示输入密钥保存位置时,输入:cat id_rsa。Pub | pbcopy 输入并确认您的密码,然后生成新的密钥。 通过运行cat ~/.ssh/id_rsa.pub通知github密钥 复制输出,然后转到github创建一个新的SSH密钥。粘贴复制的内容到文本区域,给它一个合适的标题,然后按ADD键。

现在你可以轻松地进行操作了。

除了Rufinus的回复,在Windows中将ssh密钥复制到剪贴板的快捷方式是:

id_rsa类型。Pub |剪辑

参考文献:

打印到标准输出 复制命令行输出到剪贴板

$ cd ~
$ cd .ssh
$ chmod 400 id_rsa