ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

Github项目无法通过 ssh 连接,以前正常使用的,现在无法 push pull

Github项目无法通过 ssh 连接,以前正常使用的,现在无法 push pull

Github项目无法通过 ssh 连接,以前正常使用的,现在无法 push pull

一、问题描述

2024-01-18
这两天遇到一个问题,就是以前正常使用的项目,现在无法 push 或 pull 了。
我所有的项目都是以 git@github.com:KyleBing/xxxx.git 的方式使用的,不想改成 https://

错误提示是这样的:

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.

二、解决

我将以前那种方式

git clone git@github.com:KyleBing/iphone.git iphone-vue

改成

git clone ssh://git@ssh.github.com:443/KyleBing/iphone.git iphone-vue

是可行的。

但其实有更方便的方法。

只需要在 ~/.ssh/config 中添加以下配置,以前的项目就都能正常使用了。

Host github.comHostname ssh.github.comPort 443User git

官方说明文档:
https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port

# 以这种方式使用是可以的,但不方便。
Kyle@Kyles-mbp tools % git clone ssh://git@ssh.github.com:443/KyleBing/iphone.git iphone-vue
Cloning into 'iphone-vue'...
remote: Enumerating objects: 1483, done.
remote: Counting objects: 100% (224/224), done.
remote: Compressing objects: 100% (152/152), done.
remote: Total 1483 (delta 148), reused 141 (delta 72), pack-reused 1259
Receiving objects: 100% (1483/1483), 6.00 MiB | 2.79 MiB/s, done.
Resolving deltas: 100% (936/936), done.# 其实只需要添加关于 github 的 ssh 配置
Kyle@Kyles-mbp tools % vi ~/.ssh/config# 就能测试验证成功
Kyle@Kyles-mbp tools % ssh -T git@github.com
Hi KyleBing! You've successfully authenticated, but GitHub does not provide shell access.# 之前的项目也能正常使用了。
返回列表