如何解决git push/pull操作时出现的Operation timed out

码农天地 -
如何解决git push/pull操作时出现的Operation timed out

最近git push时常出现Operation timed out,具体内容大概如下:

$ git push origin 72
ssh_dispatch_run_fatal: Connection to 192.30.255.112 port 22: Operation timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

意思是说:在连接远程地址的22端口时超时了,然后要检查权限和远程仓库是否存在。

首先在网页端是可以访问到该仓库的,所以问题并没有出在提示的权限或远程仓库

解决步骤查看远程仓库地址

查看项目下的.git/config文件,注意.git文件夹是隐藏文件夹。

[remote "origin"]
        url = git@github.com:yunzhiclub/xxxx.git
        fetch = +refs/heads/*:refs/remotes/origin/*

得出远程仓库的地址是github.com

SSH
$ ssh github.com
panjie@github.com: Permission denied (publickey).

提示权限不允许,确认网络能够访问远程主机22端口。如果不能访问,那么需要在网络上找原因了。第一先看是否能ping通,如果能ping通,则看防火墙策略是否禁用了ssh连接或22端口。

ping

网络没有问题,那问题就应该出现在证书上了。

ping github.com
panjieIMacdeiMac:app panjie$ ping github.com
PING github.com (192.30.255.112): 56 data bytes
64 bytes from 192.30.255.112: icmp_seq=0 ttl=36 time=297.969 ms

得到github.com的ip地址为192.30.255.112。

vi ~/.git/known_hosts

找到github.com,xx.xx.xxx.xxx的一条,发现xx.xx.xxx.xxx192.30.255.112并不一致,删除。

问题解决。

总结

git不上去可能是由以下原因造成的:

仓库不存在或没有权限。验证:进行网页端登录。网络问题。验证:ping一下看通不通。ssh或端口问题。验证:ssh github.com,看提示的是网络错误还是权限不允许。证书问题:验证:对比~/.ssh/known_hosts中的主机名 ip地址是否与ping的结果一致,不一致则删除。
特别申明:本文内容来源网络,版权归原作者所有,如有侵权请立即与我们联系(cy198701067573@163.com),我们将及时处理。

Tags 标签

加个好友,技术交流

1628738909466805.jpg