github ssh timeout问题解决

解决方案来源:https://bengsfort.github.io/articles/fixing-git-push-pull-timeout/
GitHub相关文档:https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port

有时候在clone或者pull GitHub上托管的repo时会出现无法连接的问题,直接报timeout错误。在这种情况下,https的clone还是可以用的,但是ssh的就不可以。根据GitHub文档解释,这可能是防火墙屏蔽了SSH到GitHub的链接。这种情况下推荐使用HTTPS端口访问ssh。

  • 问题判断:本文描述的问题会表现为github.com不可ssh连接,而ssh.github.com可以连接。可以通过一下命令检查是否时这个问题

    # 会timeout
    ssh -T -p 443 git@github.com\
    # 不会timeout,而是输出
    # Hi USERNAME! You've successfully authenticated, but GitHub does not
    # provide shell access.
    ssh -T -p 443 git@ssh.github.com
  • 解决方法:在.ssh/config中添加github的host设置

    Host github.com
    Hostname ssh.github.com
    Port 443
    User git
此条目发表在积少成多分类目录。将固定链接加入收藏夹。

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注