我用的是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上遵循了这个步骤。

第一步:检查我们是否已经拥有公共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密钥与错误的电子邮件。我可以使用ssh连接,但不能使用git。解决方案是使用我的github帐户的主要电子邮件地址重新生成密钥。

这很直接。键入下面的命令

ssh-keygen -t rsa -b 4096 -C "youremailid@yourdomain.com"

生成SSH密钥。打开文件并复制内容。进入GitHub设置页面,点击SSH key。单击“添加新的SSH密钥”,并将内容粘贴到此处。就是这样:)你不应该再看到这个问题了。

$ cd ~
$ cd .ssh
$ chmod 400 id_rsa

如果你的问题最近突然出现(2021年下半年),这可能是由不兼容的哈希算法引起的。

截至本文(2021年10月),Git for windows的最新版本是2.33.1(发布说明),它已经采用了最新的OpenSSH 8.8p1(发布说明),而OpenSSH 8.8p1反过来已经弃用了SHA-1。同时,如果远程Git存储库仍然坚持SHA-1,则身份验证将失败。

要看看你是否会陷入这种情况,检查你的软件版本:

ssh -V
git --version

然后,您应该检查OpenSSH 8.8/8.8p发行说明中的“潜在不兼容更改”部分。

博士TL;

解决方案1:通过将此添加到~/中,再次启用SHA-1。ssh /配置文件:

Host <remote>
    HostkeyAlgorithms +ssh-rsa
    PubkeyAcceptedAlgorithms +ssh-rsa

请记住将<remote>替换为远程存储库的主机名。

解决方案2:使用ECDSA或Ed25519而不是RSA重新生成密钥对。例如:

ssh-keygen -t ecdsa -C <comment>

记住用你自己的助记短语替换<comment>。然后,将生成的公钥上传到远程存储库。


供你参考,我在访问Gitee.com时遇到了这个提示信息,Gitee.com在他们的服务器上使用golang.org/x/crypto/ssh,并在这里发布了一个关于这个问题的页面(中文)。

git@gitee.com: Permission denied (publickey).

这就是我如何最终能够推动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中