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


当前回答

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

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

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

我想这是个bug。

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

其他回答

使用来自Github的ssh链接,但确保不要附加ssh,只需使用git hub上的ssh选项卡来克隆你的repo。

这对我很有效

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

请注意(至少对于某些项目),您必须拥有一个带有ssh密钥的github帐户。

查看身份验证代理中列出的密钥(ssh-add -l) (如果你没有看到任何,用ssh-add /path/到/your/key添加一个你现有的密钥(例如:ssh-add ~/.ssh/id_rsa)) (如果你没有任何密钥,首先创建一个。参见:http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/internet/node31.html或谷歌ssh-keygen)

要验证您有一个与您的github帐户相关联的密钥:

访问:https://github.com/settings/ssh

您应该至少看到一个键的哈希键与您刚才键入ssh-add -l时看到的某个哈希键相匹配。

如果没有,添加一个,然后再试一次。

我正与同样的问题作斗争,这就是我所做的,我能够克隆回购。我在Mac上遵循了这个步骤。

第一步:检查我们是否已经拥有公共SSH密钥。

打开终端。 输入ls -al ~/。查看是否存在现有的ssh密钥:

检查目录列表,查看是否已经拥有公共SSH密钥。默认public是以下d_dsa之一。酒吧,id_ecdsa。酒吧,id_ed25519。酒吧,id_rsa . pub。

如果你没有找到,那么转到步骤2,否则继续步骤3

步骤2:生成SSH公钥

Open Terminal. Enter the following command with a valid email address that you use for github ssh-keygen -t rsa -b 4096 -C "your_email@example.com" You will see the following in your terminal Generating public/private rsa key pair. When it prompts to"Enter a file in which to save the key," press Enter. This accepts the default file location. When it prompts to Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter] Just press enter again. At the prompt, "Type a secure passphrase. Enter passphrase (empty for no passphrase): [Type a passphrase]" press enter if you don't want to Enter same passphrase again: [Type passphrase again] press enter again

这将生成id_rsa.pub

步骤3:添加SSH密钥到SSH -agent

Interminal type eval "$(ssh-agent -s)" Add your SSH key to the ssh-agent. If you are using an existing SSH key rather than generating a new SSH key, you'll need to replace id_rsa in the command with the name of your existing private key file. Enter this command $ ssh-add -K ~/.ssh/id_rsa Now copy the SSH key and also add it to you github account In terminal enter this command with your ssh file name pbcopy < ~/.ssh/id_rsa.pub This will copy the file to your clipboard Now open you github account Go to Settings > SSH and GPG keys > New SSH key Enter title and paste the key from clipboard and save it. Voila you're done.

对我来说,实际的问题是使用文本编辑器复制SSH公钥到剪贴板

如果按照docs.github.com,在notepad++等文本编辑器中打开。pub文件复制SSH公钥,那么就有麻烦了。

而不是使用

猫~ / . ssh / id_ * * *。Pub |剪辑

复制命令