Git 克隆。key_load_public:无效格式权限被拒绝(公钥)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41563973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:44:34  来源:igfitidea点击:

Git clone. key_load_public: invalid format Permission denied (publickey)

gitssh

提问by Alex Pavlov

I used puttygen.exe on Windows 10 to generate private and public keys. I saved that keys in C:\Users\Alexander\.ssh\

我在 Windows 10 上使用 puttygen.exe 生成私钥和公钥。我将该密钥保存在 C:\Users\Alexander\.ssh\

Public key was added to remote repo (Not by me. I don't have an access).

公钥已添加到远程仓库(不是我的。我没有访问权限)。

Then I used command in Git Bash:

然后我在 Git Bash 中使用了命令:

git clone git@ipaddress:project_name.git

And I got an error:

我得到了一个错误:

key_load_public: invalid format
Permission denied (publickey).
fatal: Could not read from remote repository.

Example keys (generated for just for example)

示例键(仅为示例生成)

id_rsa.ppk

id_rsa.ppk

PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: rsa-key-20170110
Public-Lines: 6
AAAAB3NzaC1yc2EAAAABJQAAAQEAx0UhtZcgUT5XpoNlcoVFGHbArEsARQVCv5m0
TRh90Xq15gxOvL+x7I0B29xOuOP054RtQaOzHqnKUzpMdrIoZFkYEYJ11p42kC05
PVR/CwtKBuONJZzoIveJlNG1IhbC3G8DMZD5j68T5OVbCqftHMIBe4CTr7TewJ9T
/lmSZPytWXk/Xtcvn1i1TQZS2ShtSNOwtx77fLzkVmC6F4uM2JgJ9bSM2xQZTX/j
DYZTtoEsmyBadANAEZx4kQAoITwxXVRPBPJnB74EdSMXNhrDBJ+sZSEy7kxmc3a/
UK6CzdN3wiEMd/Bb1nuzR2cpWrWhniG66ln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EsARQVCv5m0
TRh90Xq15gxOvL+x7I0B29xOuOP054RtQaOzHqnKUzpMdrIoZFkYEYJ11p42kC05
PVR/CwtKBuONJZzoIveJlNG1IhbC3G8DMZD5j68T5OVbCqftHMIBe4CTr7TewJ9T
/lmSZPytWXk/Xtcvn1i1TQZS2ShtSNOwtx77fLzkVmC6F4uM2JgJ9bSM2xQZTX/j
DYZTtoEsmyBadANAEZx4kQAoITwxXVRPBPJnB74EdSMXNhrDBJ+sZSEy7kxmc3a/
UK6CzdN3wiEMd/Bb1nuzR2cpWrWhniG66lnOTJb3sF8iiVtw7Q==
---- END SSH2 PUBLIC KEY ----

What may be wrong here?

这里可能有什么问题?

回答by Jakuje

Git is using OpenSSH and it does not support PuTTY key formats. You need to convert it to OpenSSH format. This was described in SO documentation, now in the answer to Not able to add SSH key in Jenkins configuration:

Git 使用的是 OpenSSH,它不支持 PuTTY 密钥格式。您需要将其转换为 OpenSSH 格式。这在 SO 文档中有所描述,现在在无法在 Jenkins 配置中添加 SSH 密钥的答案

  • Open PuttyGen
  • Click Load
  • Load your private key
  • Go to Conversions->Export OpenSSHand export your private key
  • Copy your private key to ~/.ssh/id_rsa
  • 打开 PuttyGen
  • 点击加载
  • 加载你的私钥
  • 转到转换->导出 OpenSSH并导出您的私钥
  • 将您的私钥复制到 ~/.ssh/id_rsa

回答by Nick Misner

Sorry for answering an old question, but the listed solutions didn't help. Here's what worked for me:

很抱歉回答一个老问题,但列出的解决方案没有帮助。以下是对我有用的内容:

Git may not be using the correct SSH client for outgoing connections.

Git 可能没有使用正确的 SSH 客户端进行传出连接。

I was having a similar issue and ended up finding an answerthat set me on the right track to fix it. From what I understand, both Git & My command line where generating key-pairs using openssh, but Git was attempting to open them using it's own SSH client.

我遇到了类似的问题,最终找到了一个答案,让我走上了修复它的正确轨道。据我所知,Git 和我的命令行都使用 openssh 生成密钥对,但 Git 试图使用它自己的 SSH 客户端打开它们。

I'm not sure why Git would use two different ssh clients, one for generating, one for connecting, but this was evidenced by being able to verify my key by opening an SSH session to GitHub, but not connect to a repository. A further check seemed to validate the theory:

我不确定为什么 Git 会使用两个不同的 ssh 客户端,一个用于生成,一个用于连接,但这可以通过打开到 GitHub 的 SSH 会话来验证我的密钥来证明,但不能连接到存储库。进一步的检查似乎证实了该理论:

C:\where ssh
C:\Windows\System32\OpenSSH\ssh.exe

And in git bash:

在 git bash 中:

$ where ssh
C:\Program Files\Git\usr\bin\ssh.exe

While trying the commands listed in the answer didn't fix my problem, they led me on a much more successful google search that got me to this GitHub comment,which contained the following single line command, to be run in git bash:

虽然尝试答案中列出的命令并没有解决我的问题,但他们引导我进行了更成功的谷歌搜索,让我找到了这个 GitHub 评论,其中包含以下单行命令,可以在 git bash 中运行:

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

This command will not output anything if it works, but it will set git to use the ssh client packaged with windows instead of the one included with git. After running this command, Git worked flawlessly for me.

如果这个命令有效,它不会输出任何内容,但它会设置 git 使用 Windows 打包的 ssh 客户端,而不是 git 包含的客户端。运行此命令后,Git 对我来说完美无缺。

Weirdly enough, running "where ssh" in git bash now returns two paths, but it doesn't seem to be causing any more issues:

奇怪的是,在 git bash 中运行“where ssh”现在返回两条路径,但它似乎不会引起更多问题:

$ where ssh
C:\Program Files\Git\usr\bin\ssh.exe
C:\Windows\System32\OpenSSH\ssh.exe

回答by Raz

Verify the next things:

验证接下来的事情:

  1. Check if you have an empty id_rsa.pubfile in the ~/.sshdirectory. There could be more than one .pub files in there (depend on what you have already created). If you find a blank .pub file, go to where it should be kept in a remote server, in the ~/.ssh/authorized_keysfile (on the server). Copy it's values and paste in your local public key file. Save.

  2. If everything correct in your local public keys, check that you didn't pasted the private key to your server or something.

  1. 检查目录中是否有空id_rsa.pub文件~/.ssh。那里可能有多个 .pub 文件(取决于您已经创建的内容)。如果您找到一个空白的 .pub 文件,请转到~/.ssh/authorized_keys文件中(在服务器上)应将其保存在远程服务器中的位置。复制它的值并粘贴到您的本地公钥文件中。节省。

  2. 如果本地公钥中的一切都正确,请检查您是否没有将私钥粘贴到服务器或其他东西。