git@gitlab.com: Permission denied (publickey).致命:无法从远程存储库读取.



我有以下问题。我想从我们的GitLab实例克隆一个repo,然而,我得到以下错误:git@gitlab.com: Permission denied (publickey). fatal: Could not read from remote repository.

我已经花了几个小时在网上搜索,但没有一个解决方案对我有用。

更多信息:Win10, WSL2

我到目前为止的进展情况:

ssh-keygen -t ed25519 -C "your_email@example.com"
exec ssh-agent bash
ssh-add ~/.ssh/id_ed25519

源(https://docs.github.com/de/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent?platform=linux)

Then Add the publickey to GitLab.

然而,我不会工作。

的输出
ssh -Tv git@gitlab.com
OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /home/<user>/.ssh/config
debug1: /home/<user>/.ssh/config line 1: Applying options for gitlab.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to gitlab.com [<ip-adress>] port 22.
debug1: Connection established.
debug1: identity file /home/<user>/.ssh/id_rsa.pub type -1
debug1: identity file /home/<user>/.ssh/id_rsa.pub-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.5
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
debug1: Authenticating to gitlab.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:ATGbzTPAlJZOY5gURztKPIuzAC/eN22PApBTfUW8oQA
debug1: Host 'gitlab.com' is known and matches the ECDSA host key.
debug1: Found key in /home/<user>/.ssh/known_hosts:13
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /home/<user>/.ssh/id_rsa.pub  explicit
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/<user>/.ssh/id_rsa.pub
no such identity: /home/<user>/.ssh/id_rsa.pub: No such file or directory
debug1: No more authentication methods to try.
git@gitlab.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

在我试图解决这个问题的过程中,我写了一个配置文件,看起来像这样:

Host <myhost>
HostName <myhostname>
User <username>
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_ed25519.pub
PubkeyAcceptedKeyTypes=+ssh-rsa
TCPKeepAlive Yes

请注意,我必须审查一些输出。

如果你有什么可以帮助我的主意,我很乐意听听。

编辑:根据回复中提供的步骤,我现在可以使用WSL进行克隆,但不能使用giitbash。

配置文件应为:

Host mygitlab                  <===
HostName gitlab.com        <===
User git                   <===
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_ed25519.pub
PubkeyAcceptedKeyTypes=+ssh-rsa
TCPKeepAlive Yes

测试应该是:

ssh -Tv mygitlab

或:

git clone mygitlab:<me>/<myrepo>

最新更新