Gitlab密钥格式问题

Gitlab key format issue

我遇到了一个奇怪的情况,我正在使用 gitlab 帐户来处理我的代码。我正在使用 ssh 协议访问存储库。我能够提取代码,但在尝试推送代码时收到以下错误。这对我来说可能是愚蠢的。但是 我将密钥存储在我的 gitlab 配置文件中 并且 能够 使用它来 提取代码

错误:

$ git push origin master
key_load_public: invalid format
Enter passphrase for key '/c/Users/username/.ssh/id_rsa':
Access denied.
fatal: Could not read from remote repository.

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

如果你上传 'vanilla' putty 密钥,解决方案可能描述如下:https://gitlab.com/gitlab-org/gitlab-ce/issues/786

我终于解决了这个问题,我将它发布给其他用户。如果 putty 生成的密钥无法帮助您访问 gitlab 存储库,请尝试使用命令 [=10= 从 gitbash 终端生成密钥] 并将文件保存在您用户帐户的 .ssh 文件夹中。

linux 样式密钥生成让我的生活变得轻松,因为我试图在 windows 环境中使用 putty keygen 生成密钥。

希望这对某人有所帮助。

PuTTYGen 可以生成正确的 OpenSSH 密钥。

  1. 生成您的密钥文件,保存私钥(带或不带密码)
  2. 添加您的 username/email 地址作为评论
  3. 复制生成的密钥的内容并将其粘贴到您的 id_rsa.pub
  4. 使用菜单导出OpenSSH私钥并保存为id_rsa

我通过从我的私钥 (id_es) 重新生成我的 public 密钥 (id_es.pub) 修复了我的错误:

ssh-keygen -f ~/.ssh/id_es -y > ~/.ssh/id_es.pub
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "my.email@example.com"
AAAAB3NzaC1ycxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxx=
---- END SSH2 PUBLIC KEY ----

目前,您必须手动提取密钥(删除其他行)并在其前面添加“ssh-rsa”。所以就像

ssh-rsa AAAAB3NzaC1ycxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxx=

如果Gitlab能自动完成就更方便了

https://gitlab.com/gitlab-org/gitlab-foss/-/issues/786