ssh: connect to host github.com port 22: Operation timed outfatal: Could not rea

63 阅读1分钟

背景

git 推送/拉取代码到github仓库时发生错误。

  1. git push
ssh: connect to host github.com 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.
  1. git clone
致命错误:无法访问 'https://github.com/ldf-fan/ldf-blog.git/':Failed to connect to github.com port 443 after 75002 ms: Couldn't connect to server

问题处理

查看ssh链接

ssh -T git@github.com

报错:端口连接超时。

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

后续流程

找到.ssh文件夹,Mac中路径是 ~/.ssh,新建一个config文件,不带后缀。

touch config

打开config文件,添加下列代码,注意User后面的邮箱改为你的邮箱。

Host github.com
User xxx@163.com
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

再次执行下面代码:

ssh -T git@github.com

显示下面提示:

The authenticity of host '[ssh.github.com]:443 ([20.200.200.100]:443)' can't be established.
ECDSA key fingerprint is SHA256:XXXXXXXX/XXXXXX/XXXXXXX.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[ssh.github.com]:443,[20.200.200.100]:443' (ECDSA) to the list of known hosts.

再次执行:

ssh -T git@github.com

回应下面消息,说明成功了。

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

接下来就可以正常推送代码了。