Github - can't connect via ssh from time to time

只愿长相守 提交于 2019-12-21 17:29:00

问题


Situation

I'm using linux (mint mate 17.2), when push to github via ssh, from time to time connection fails, usually it resume after reboot computer & network. After several days, it might become bad again, quite confusing.

Push via http never has such issue, but it requires password which is not convenient.

Debug info

When push via ssh:

debug1: Connecting to github.com [192.30.252.129] port 22.

It stuck at the above line.

Then after a long wait, get timeout tip:

debug1: connect to address 192.30.252.129 port 22: Connection timed out

ssh: connect to host github.com port 22: Connection timed out

fatal: Could not read from remote repository.

Questions:

What could be the reason, how to fix that?


More debug info:

ping is good:

eric@eric-pc:~$ ping 192.30.252.129
PING 192.30.252.129 (192.30.252.129) 56(84) bytes of data.
64 bytes from 192.30.252.129: icmp_seq=1 ttl=50 time=345 ms
64 bytes from 192.30.252.129: icmp_seq=2 ttl=50 time=452 ms
64 bytes from 192.30.252.129: icmp_seq=3 ttl=50 time=373 ms
64 bytes from 192.30.252.129: icmp_seq=4 ttl=50 time=349 ms
64 bytes from 192.30.252.129: icmp_seq=5 ttl=50 time=346 ms
64 bytes from 192.30.252.129: icmp_seq=6 ttl=50 time=442 ms
64 bytes from 192.30.252.129: icmp_seq=7 ttl=50 time=344 ms

telnet is bad:

eric@eric-pc:~$ telnet 192.30.252.129 22
Trying 192.30.252.129...

@Update:

I setup another computer in the same network, with the same ssh key, it succeed to push to github via ssh, while the original computer still get timeout.

Actions:

  • Restart the network, it still can't connect.

  • Restart the ssh-agent, it still can't connect, the old process become a defunct ssh-agent process, while there is a new ssh-agent:

    eric      2552  0.0  0.0      0     0 ?        Zs   Jan08   0:00 [ssh-agent] 
    eric     27080  0.0  0.0  10628   316 ?        Ss   15:26   0:00 ssh-agent
    eric     27168  0.0  0.0  17028  2548 pts/7    S+   15:27   0:00 grep --color=auto ssh-agent

  • Reboot linux, then ssh works,

Guess:

  • ssh-agent has issue,
  • github blocked my client due to some reason,

Actually, before ask, from google, I saw similar question, but none solved the issue, and none explained the reason.

And this issue is really annoying, because I don't want to input password every time push, and also don't want to reboot my pc from time to time, any help?


回答1:


Try changing your git default ssh port using the command $ git remote add origin ssh://user@host:1234/srv/git/example and your ssh port to 1234. you can use anyother port you like rather than 1234 (larger than 1000 are recommended).see if it can solve your problem. :)

.try changing your ~/.ssh/config file if doesn't exit create one.

Host github.com Port 22 Host * Port 1234



来源:https://stackoverflow.com/questions/34736817/github-cant-connect-via-ssh-from-time-to-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!