2024-01-18
这两天发现无法跟 github 交互了,我所有的项目都是以 [email protected]:KyleBing/xxxx.git
的方式使用的,不想改成 https:// 。
反正现在是无法 push | pull 了,本地电脑和服务器的 ssh key 都已加到了 github 账户中,以前正常使用的,这两天都不行了,不知道什么原因,有遇到这种情况的没有?是 github 抽了?我电脑抽了?
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 ssh://[email protected]:KyleBing/iphone.git iphone-vue
改成
git clone ssh://[email protected]:443/KyleBing/iphone.git iphone-vue
是可行的。
但其实有更方便的方法。
只需要在 ~/.ssh/config
中添加以下配置,以前的项目就都能正常使用了。
Host github.com Hostname ssh.github.com Port 443 User git
官方说明文档: https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port
# 以这种方式使用是可以的,但不方便。 Kyle@Kyles-mbp tools % git clone ssh://[email protected]: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 [email protected] Hi KyleBing! You've successfully authenticated, but GitHub does not provide shell access. # 之前的项目也能正常使用了。
谢 v 友解答
![]() | 1 misaka19000 2024-01-18 09:33:41 +08:00 via Android 挂梯子 |
2 horizon 2024-01-18 09:38:37 +08:00 ![]() |
![]() | 3 lizy0329 2024-01-18 09:42:08 +08:00 ![]() |
![]() | 4 coderpwh 2024-01-18 09:50:38 +08:00 ![]() 我也是,后来看了 gitconfig 发现被改了,少了 github 的 host,加上就好,应该是升级 git 导致的 |
![]() | 5 kylebing OP @horizon @lizy0329 @coderpwh 可行,只需要 在 ./ssh/config 添加对应 github 的配置就好了 https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port#enabling-ssh-connections-over-https |
![]() | 6 weijancc 2024-01-18 10:18:06 +08:00 就是被墙了, 我也一样, 挂梯子解决 |
7 CHAOFY 2024-01-18 10:25:48 +08:00 我挂了梯子还是不行,最后用楼上的方法解决的。 |
9 32uKHwVJ179qCmPj 2024-01-18 10:32:59 +08:00 挂梯子不行是因为 ssh 协议没走梯子,改成 https 或者用 tun 模式应该就行 |
![]() | 10 rowG 2024-01-18 10:37:50 +08:00 我昨天也遇到了,也是用 config 文件那种方法解决的。 我还以为是公司网络端口的问题 |
11 yyancy517 2024-01-18 10:40:00 +08:00 我昨天也遇到了, 晚上回去试试 github 给的方案 |
![]() | 12 BaseException 2024-01-18 10:41:34 +08:00 ![]() 443 clone, 写 C:\Users\xxx\.ssh\config 文件,这样更好用。 借楼宣传我写的这篇文章了 [2022.03] GitHub 加速终极教程 https://hellodk.cn/post/975 |
13 yyancy517 2024-01-18 10:51:09 +08:00 为什么回复不了 |
14 yyancy517 2024-01-18 10:51:58 +08:00 ![]() @BaseException #12 好文章, 总结的不错. 晚上我回去试试看行不行 |
![]() | 15 uncat 2024-01-18 11:17:25 +08:00 ![]() 如果你有一台非中国大陆地区的服务器,假设信息如下: 地址是:1.2.3.4 用户名是:root 把本地的 SSH 公钥添加到服务器上,然后在本地 ~/.ssh/config 内添加: Host github.com gitlab.com ProxyJump [email protected] 即可(所有平台都可以,包括 Windows ,Windows 在 PowerShell 内操作) 不用依赖任何本地工具(比如 netcat) |
![]() | 16 uncat 2024-01-18 11:19:02 +08:00 git 协议实际上是基于 SSH 的,上面的配置,是基于 1.2.3.4 进行 SSH 流量中专( ProxyJump )的意思。 |
![]() | 17 licoycn 2024-01-18 11:39:01 +08:00 直接同步一下 github 的 hosts ,就可以了,简单粗暴: https://github.com/Licoy/fetch-github-hosts |
![]() | 18 wdssmq 2024-01-18 12:00:51 +08:00 现在还好,但是去年大半年时间内也是连不上。。让 ssh 走代理的姿势如下。。 Host git HostName github.com User git ProxyCommand "C:\Program Files\Git\mingw64\bin\connect.exe" -S 127.0.0.1:10808 %h %p 443 端口以及 15 楼的方式万一下次遇上感觉也可以试下。。 |
![]() | 21 codelover612 2024-01-18 14:03:01 +08:00 via iPhone 我也是,梯子解决 |
![]() | 22 equationzhao 2024-01-18 14:10:56 +08:00 @BaseException 感谢 |
![]() | 23 demonchang 2024-01-18 14:13:57 +08:00 我是改 hosts 140.82.112.3 github.com |
25 susheng 2024-01-20 00:43:34 +08:00 @demonchang 这个可行,问下 ip 怎么找的? |
![]() | 26 demonchang 2024-01-22 09:21:32 +08:00 @susheng 也是网上搜的 |
![]() | 27 GodVan 2024-01-22 15:15:54 +08:00 6 ,lz 的方法可用! |
28 xinshoushanglu 2024-01-26 16:28:35 +08:00 太蛋疼了,github 突然改了这个,我挂代理 也是 git 命令全部不通 |
29 xinshoushanglu 2024-01-26 16:55:26 +08:00 先本地加 hosts 的 github 解析记录了,太蛋疼了,挂代理 ssh git 都不行 |