从gitlab拉/推导致权限被拒绝(公钥)

时间:2020-06-15 20:37:07

标签: git ssh gitlab public-key

我同时使用git bash和VS代码连接到我的gitlab存储库。一切运行良好,直到我创建了一个新的存储库并尝试通过git bash在本地克隆它。 我收到的错误是:

git@gitlab.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

我尝试更改./ssh文件夹和公共密钥的权限,向代理添加ssh,但这些都不起作用。

执行ssh -Tv <user name>@gitlab.com显示以下输出:

OpenSSH_8.2p1, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to gitlab.com [172.65.251.78] port 22.
debug1: Connection established.
debug1: identity file /c/Users/user/.ssh/id_rsa type 0
debug1: identity file /c/Users/user/.ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.8
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.8 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 'user'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
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:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw
debug1: Host 'gitlab.com' is known and matches the ECDSA host key.
debug1: Found key in /c/Users/user/.ssh/known_hosts:7
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: pubkey_prepare: ssh_get_authentication_socket: Bad file descriptor
debug1: Will attempt key: /c/Users/user
/.ssh/id_rsa RSA SHA256:rNZDTqdiVzM9+qjPlPV9wpd5Eg0t0tKKMonz+Q6+yGo
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
debug1: Next authentication method: publickey
debug1: Offering public key: /c/Users/user/.ssh/id_rsa RSA SHA256:rNZDTqdiVzM9+qjPlPV9wpd5Eg0t0tKKMonz+Q6+yGo
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
<user name>@gitlab.com: Permission denied (publickey).

1 个答案:

答案 0 :(得分:0)

我尝试更改./ssh文件夹和公共密钥的权限,向代理添加ssh,但这些都不起作用。

首先,请确保您拥有registered the content of id_rsa.pub to your GitLab SSH keys profile page

如果仍然无法正常运行,请尝试重新生成该密钥,而无需设置密码(进行测试,并排除所有ssh-agent问题,该问题仅用于缓存密码)

ssh-keygen -m PEM -t rsa -P ""

确保您的Git for Windows是最新的(2.27)。

请确保进行set GIT_SSH=(意味着取消设置 GIT_SSH,不应引用putty.exe)。