【git error fix 】git@github.com: Permission denied (publickey).
git不能clone,报错:
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
以为是key的问题。重新配置了key仍然报错。
使用如下命令查看问题:
$ ssh -v git@github.com
显示内容:
OpenSSH_8.3p1, OpenSSL 1.1.1g 21 Apr 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [222.42.5.41] port 22.
debug1: Connection established.
debug1: identity file /.ssh/id_rsa type 0
debug1: identity file /.ssh/id_rsa-cert type -1
debug1: identity file /.ssh/id_dsa type -1
debug1: identity file /.ssh/id_dsa-cert type -1
debug1: identity file /.ssh/id_ecdsa type -1
debug1: identity file /.ssh/id_ecdsa-cert type -1
debug1: identity file /.ssh/id_ecdsa_sk type -1
debug1: identity file /.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /.ssh/id_ed25519 type -1
debug1: identity file /.ssh/id_ed25519-cert type -1
debug1: identity file /.ssh/id_ed25519_sk type -1
debug1: identity file /.ssh/id_ed25519_sk-cert type -1
debug1: identity file /.ssh/id_xmss type -1
debug1: identity file /.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.3
debug1: Remote protocol version 2.0, remote software version babeld-5ac2f1c7
debug1: no match: babeld-5ac2f1c7
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: rsa-sha2-512
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: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /.ssh/known_hosts:1
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: /.ssh/id_rsa RSA SHA256:RaLgLbrH0tzriJxznCFpCnTB5lBIYVzuuNWU+wcnOOM
debug1: Will attempt key: /.ssh/id_dsa
debug1: Will attempt key: /.ssh/id_ecdsa
debug1: Will attempt key: /.ssh/id_ecdsa_sk
debug1: Will attempt key: /.ssh/id_ed25519
debug1: Will attempt key: /.ssh/id_ed25519_sk
debug1: Will attempt key: /.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /.ssh/id_rsa RSA SHA256:RaLgLbrH0tzriJxznCFpCnTB5lBIYVzuuNWU+wcnOOM
debug1: Authentications that can continue: publickey
debug1: Trying private key: /.ssh/id_dsa
debug1: Trying private key: /.ssh/id_ecdsa
debug1: Trying private key: /.ssh/id_ecdsa_sk
debug1: Trying private key: /.ssh/id_ed25519
debug1: Trying private key: /.ssh/id_ed25519_sk
debug1: Trying private key: /.ssh/id_xmss
debug1: No more authentication methods to try.
git@github.com: Permission denied (publickey).
(base)
注意到ERROR信息:
debug1: Found key in /.ssh/known_hosts:1
发现已经存在key,查看./ssh文件夹:
yanghang@DESKTOP-0VQUS2J MINGW64 /
$ ls
bin/ cmd/ dev/ etc/ git-bash.exe* git-cmd.exe* LICENSE.txt magic.py mingw64/ proc/ ReleaseNotes.html tmp/ unins000.dat unins000.exe* unins000.msg usr/
(base)
发现没用./ssh文件夹,准备建立./ssh重新配置:
yanghang@DESKTOP-0VQUS2J MINGW64 /
$ mkdir .ssh
mkdir: cannot create directory ‘.ssh’: File exists
(base)
提示已存在。
进入文件夹,发现老key,使用原有key完成配置:
yanghang@DESKTOP-0VQUS2J MINGW64 /.ssh
$ ls
id_rsa id_rsa.pub known_hosts
(base)
问题解决:
yanghang@DESKTOP-0VQUS2J MINGW64 /d/0-WORK/L3+ (master)
$ git clone git@github.com:xxxx
Cloning into 'xxxx'...
remote: Enumerating objects: 55, done.
remote: Counting objects: 100% (55/55), done.
remote: Compressing objects: 100% (44/44), done.
remote: Total 559 (delta 8), reused 47 (delta 7), pack-reused 504
Receiving objects: 100% (559/559), 55.65 MiB | 244.00 KiB/s, done.
Resolving