您现在的位置是:首页 >技术交流 >git clone/push 失败:ssh: connect to host github.com port 22: Connection timed out网站首页技术交流

git clone/push 失败:ssh: connect to host github.com port 22: Connection timed out

MurphyChen233 2025-08-23 12:01:04
简介git clone/push 失败:ssh: connect to host github.com port 22: Connection timed out

之前 git ssh 正常使用,今天突然报了这个错,报错信息如下:

➜ git clone git@github.com:Hacker-C/notes.git
Cloning into 'notes'...
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.

试了网上说几种方法( SSH 更换 443 端口、换网络热点、换 github ssh ip)都没用,但是我们最终都是为了使用 git push,那就用 https 的方式好了。

1、使用 HTTPS 方式克隆和推送代码:

git clone https://github.com/你的用户名/你的仓库.git

2、然后配置 Git 用 HTTPS 认证:

git config --global credential.helper store

3、推送时会要求你输入 GitHub 账户的 Token

密码认证已被 GitHub 禁用,需要在 GitHub 个人令牌 生成一个 Personal access tokens (classic),然后使用它作为 Git 密码。记得选择 repo 相关的读写权限。

4、push 代码时提示输入用户名和密码,密码输入刚才生成的 token。git 记住这次的凭证,后面不用再次输入了

风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。