问题复现
$ ssh -T git@github.com
Permission denied (publickey).
本地刚创建ssh密钥进行连接时发现如上报错
排错过程
- 使用以下命令看有没有known_hosts文件
ls ~/.ssh/
2. 打开known_hosts文件看有没有我们ssh密钥如下
这里需要比对ip地址(公网地址),密钥key是不是和我们生成的xx.pub里面的内容是否一致
- 查看ssh连接debug日志
ssh -v git@github.com
OpenSSH_7.1p2, OpenSSL 1.0.2d 9 Jul 2015
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [13.250.177.223] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/skindow/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/skindow/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/skindow/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/skindow/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/skindow/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/skindow/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/skindow/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/skindow/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.1
debug1: Remote protocol version 2.0, remote software version babeld-dae25663
debug1: no match: babeld-dae25663
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client chacha20-poly1305@openssh.com <implicit> none
debug1: kex: client->server chacha20-poly1305@openssh.com <implicit> 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 /c/Users/skindow/.ssh/known_hosts:1
Warning: the RSA host key for 'github.com' differs from the key for the IP address '13.250.177.223'
Offending key for IP in /c/Users/skindow/.ssh/known_hosts:3
Matching host key in /c/Users/skindow/.ssh/known_hosts:1
Are you sure you want to continue connecting (yes/no)?
Host key verification failed.
通过上面日志我们发现,一直在寻找文件 /c/Users/skindow/.ssh/id_rsa ,id_rsa该文件是你生成密钥的文件如下(缺少该密钥文件id_rsa导致的报错)
我们只需要将该文件放在 /c/Users/skindow/.ssh/目录下,并将名字改成id_rsa即可如下
修改玩之后我们再次尝试连接,并进行同步
文件成功拉取,错误完美解决!