ssh类型的仓库,git clone/pull报错:kex_exchange_identification: Connection closed by remote host
1 2 3 4 5 6 7
| git pull kex_exchange_identification: Connection closed by remote host Connection closed by 127.0.0.1 port 7890 fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
|
这个报错其实跟使用梯子有关。
解决:
step 1.将~/.ssh下的id_rsa.pub(没有就先创建公私钥)公钥内容添加到github后台。
step 2.在~/.ssh/config文件(没有就先创建)中添加:
1 2 3 4
| Host github.com HostName ssh.github.com User git Port 443
|
上述内容表示ssh使用443端口而不再是默认的22。
step 3.使用命令ssh -T git@github.com
验证
1 2
| $ ssh -T git@github.com Hi xq-120! You've successfully authenticated, but GitHub does not provide shell access.
|
这个时候应该就可以正常git clone了。
其实上面执行完后,会在known_hosts添加记录:
1 2 3
| [ssh.github.com]:443 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl [ssh.github.com]:443 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk= [ssh.github.com]:443 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=
|
这就是所谓的host key fingerprint,其实就是用来验证服务器身份的,避免中间人攻击。
另外不知道为啥还生成了一个known_hosts.old文件。
其他
查看仓库的远程URL类型
打印结果:一般是ssh或https
1 2
| origin ssh://git@github.com/xxx/xxx.git (fetch) origin ssh://git@github.com/xxx/xxx.git (push)
|
1 2
| origin https://github.com/xxx/xxx.git (fetch) origin https://github.com/xxx/xxx.git (push)
|
参考
Github:通过sshkey的方式拉取代码报错kex_exchange_identification: Connection closed by remote