Git 使用Https 和 SSH 连接不到 service 问题修复

741 阅读1分钟
  • 修复 git 使用 https pull 和 clone 时出现的下面的错误:

    unable to access 'https://github.com/xxx.git/': Failed to connect to github.com port 443 after 21088 ms: Couldn't connect to server
    

    这是由于网络代理出现的问题,添加 http.proxy 可以解决该问题, 如

     git config --global http.proxy 127.0.0.1:8087
    

    8087 是代理的端口号

  • 修复 git 使用 ssh pull 和 clone 出现下面的错误

     ssh: connect to host github.com port 22: Connection timed out
     fatal: Could not read from remote repository.
    

    修复步骤:

    1. 先确保 git 通过 https pull 和 clone 没有问题

    2. 添加 .ssh/config 文件, 内容如下:

         Host github.com
         Hostname ssh.github.com
         Port 443
         User git
      
    3. 运行 ssh -T git@github.com, 然后按提示进行操作。

    4. 再次运行ssh -T git@github.com, 如果出现下面的信息表示成功

      Hi username! You've successfully authenticated, but GitHub does not provide shell access.