GitHub-fatal-unable-to-access-https-github-com-Failed-to-connect-to-github-com-port-443-Operation-timed-out-CarlZeng

发布时间 2023-11-12 09:31:48作者: CarlZeng
title: >-
  [GitHub] fatal: unable to access 'https://github.com/': Failed to connect to
  github.com port 443: Operation timed out
tags: [github,git]
categories: github
date: 2021-11-23 11:11:00

2021年11月,由于众所周知的缘故,连接到github越来越微妙,分享一些MAC平台上的解题思路,希望对你有帮助:

Errors

Notes:

Don't verify the operation in editor(WebStorm,IntelliJ IDEA...etc), use command(Mac's terminal.app), use terminal.app


Solutions for: Operation timed out

  1. Fix the hosts to make sure the ssh connection between your Computer and github.com is availble(修复连接到github.com)

Verify Standard 判断标准:$ ssh -T git@github.com

1.1 记录下github的IP地址, 把IP Address 记录下来

打开https://github.com.ipaddress.com/

打开https://fastly.net.ipaddress.com/github.global.ssl.fastly.net#ipinfo

打开https://github.com.ipaddress.com/assets-cdn.github.com

1.2 打开电脑的hosts文件(/private/etc/hosts),把下列的地址对应写入,然后保存即可(version2021.11.23)

# Github Start. Updated 20211123/CZ 140.82.113.3 github.com 199.232.69.194 github.global.ssl.fastly.net 185.199.108.153 assets-cdn.github.com 185.199.109.153 assets-cdn.github.com 185.199.110.153 assets-cdn.github.com 185.199.111.153 assets-cdn.github.com

Github End

1.3 在终端在输以下指令刷新DNS(需要权限)

sudo killall -HUP mDNSResponder

1.4 如果之前用ssh proxy,取消它

git config --global http.proxy http://127.0.0.1:1080 
git config --global https.proxy http://127.0.0.1:1080 
git config --global --unset http.proxy
git config --global --unset https.proxy

1.5 重新尝试 ping github.com. 重新尝试 ssh -T git@github.com

新的错误可能和授权有关,至少证明连接到github.com是通的。


Solutions for: Authentication

  1. Create new Token and login to github.com (新建密钥并登陆进github.com)

Verify Standard 判断标准:$ git pull

2.1 Creating a personal access token at https://github.com/settings/tokens

授权_admin:org, admin:public_key, admin:repo_hook, gist, read:user, repo, write:packages_

具体步骤:https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

2.2 Terminal.app 命令行,运行 git pull(先要cd 到原来的git 根目录)

Username for 'https://github.com':  (这个地方输入登录github网址用的用户名,我的是用9个英文字母)
Password for 'https://***@github.com':  (这个地方要是输入#2.1中得到的Token)

2.3 判断一下连接和授权,如果需要ssh连接,继续添加配置以下。

2.4 生成ssh密钥。Generating a new SSH key and adding it to the ssh-agent。具体步骤简要如下:

$ ssh-keygen -t ed25519 -C "your\_email@example.com"

> Enter a file in which to save the key (/Users/you/.ssh/id\_algorithm): \[Press enter\] \> Enter passphrase (empty for no passphrase): \[Type a passphrase\] \> Enter same passphrase again: \[Type passphrase again\] \---------------------------------------------------- $ eval "$(ssh-agent -s)"
> Agent pid 59566

---------------------------------------------------- $ touch ~/.ssh/config  
加入以下内容:
Host \* AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id\_ed25519 \---------------------------------------------------- $ ssh\-add -K ~/.ssh/id\_ed25519

2.5 协助排查:github服务端的日志,显示有用的连接信息,用来验证链路是否握手成功等等

https://github.com/settings/security-log

尽量把验证都放在命令行中,这样更高效直接(在IDE中操作,在验证太费劲了),terminal成功以后,IDEA会自动也成功,因为它们分享相同的配置(git 根目录下面有.git的配置目录)

参见文档:

https://juejin.cn/post/6844904193170341896

https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/

Node.js也被同样错误卡

hexo d
...
fatal: unable to access 'https://github.com/@@@@@.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
...

{% tabs 尝试%}

git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy http://127.0.0.1:1080
重试hexo d

git config --global --unset http.proxy
git config --global --unset https.proxy
重试hexo d

{% endtabs %}

解决办法后来是因为hexo没有检测到内容变动,不去push。
hexo clean
然后在 hexo g && hexo d 就解决了