Github拉取项目报错解决

发布于:2025-02-11 ⋅ 阅读:(66) ⋅ 点赞:(0)

前言

昨天在拉取github上面的项目报错了,有好几个月没用github了,命令如下:

git clone git@github.com:zhszstudy/git-test.git

报错信息:

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

Please make sure you have the correct access rights
and the repository exists.

我重新设置github上的ssh key,梯子也开了还是报这个错,换成https链接拉取也报错,查阅资料发现,此错误信息为不能通过 22 端口连接到 GitHub

解决方法

  1. 执行以下命令:
ssh -T git@github.com

出现以下信息说明通过22端口连接github超时:

ssh: connect to host github.com port 22: Connection timed out
  1. 将 SSH 连接的端口更改为 443:
ssh -T -p 443 git@ssh.github.com

出现以下信息,表示通过 443 端口成功进行了身份验证,但GitHub不提供shell访问权限:

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

如果出现以下信息,则需要回复yes,如果输出上面的信息表示成功:

The authenticity of host '[ssh.github.com]:443 ([20.205.243.160]:443)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Host key verification failed.
  1. 在密钥目录下新建文件config,编写以下内容:
Host github.com
  Hostname ssh.github.com
  Port 443

在这里插入图片描述

  1. 重新执行以下命令:
ssh -T git@github.com

出现以下信息表示成功:

Hi xxxxx! You've successfully authenticated, but GitHub does not provide shell access.
  1. 重新拉取项目,可以看到已经拉取成功了:
$ git clone git@github.com:zhszstudy/git-test.git
Cloning into 'git-test'...
remote: Enumerating objects: 118, done.
remote: Counting objects: 100% (118/118), done.
remote: Compressing objects: 100% (29/29), done.
remote: Total 118 (delta 12), reused 109 (delta 11), pack-reused 0 (from 0)
Receiving objects: 100% (118/118), 7.90 KiB | 476.00 KiB/s, done.
Resolving deltas: 100% (12/12), done.

网站公告

今日签到

点亮在社区的每一天
去签到