繁体   English   中英

git@gitlab.com:权限被拒绝(公钥)。 致命:无法从远程存储库读取

[英]git@gitlab.com: Permission denied (publickey). fatal: Could not read from remote repository

我有以下问题。 我想从我们的 GitLab 实例克隆一个 repo,但是,我收到以下错误: git@gitlab.com: Permission denied (publickey). fatal: Could not read from remote repository. 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?平台=linux

然后将公钥添加到 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 进行克隆,但不能使用 Gitbash。

配置文件应该是:

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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM