V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
kylebing
V2EX  ›  GitHub

好奇怪,这两天 github 通过 ssh 的方式无法 push 或 pull 了

  •  2
     
  •   kylebing ·
    KyleBing · Jan 18, 2024 · 5016 views
    This topic created in 841 days ago, the information mentioned may be changed or developed.

    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.
    
    Supplement 1  ·  Jan 18, 2024

    已解决

    我将以前那种方式

    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 友解答

    Supplement 2  ·  Jan 18, 2024

    success

    29 replies    2024-01-26 16:55:26 +08:00
    misaka19000
        1
    misaka19000  
       Jan 18, 2024 via Android
    挂梯子
    horizon
        2
    horizon  
       Jan 18, 2024   ❤️ 3
    lizy0329
        3
    lizy0329  
       Jan 18, 2024   ❤️ 1
    coderpwh
        4
    coderpwh  
       Jan 18, 2024   ❤️ 1
    我也是,后来看了 gitconfig 发现被改了,少了 github 的 host,加上就好,应该是升级 git 导致的
    kylebing
        5
    kylebing  
    OP
       Jan 18, 2024
    weijancc
        6
    weijancc  
       Jan 18, 2024
    就是被墙了, 我也一样, 挂梯子解决
    CHAOFY
        7
    CHAOFY  
       Jan 18, 2024
    我挂了梯子还是不行,最后用楼上的方法解决的。
    weijancc
        8
    weijancc  
       Jan 18, 2024
    @CHAOFY 我想你只是开了全局代理, 需要使用 VPN 或者 tap 模式走流量, ssh 是不走全局代理的
    32uKHwVJ179qCmPj
        9
    32uKHwVJ179qCmPj  
       Jan 18, 2024
    挂梯子不行是因为 ssh 协议没走梯子,改成 https 或者用 tun 模式应该就行
    rockjaylee
        10
    rockjaylee  
       Jan 18, 2024
    我昨天也遇到了,也是用 config 文件那种方法解决的。
    我还以为是公司网络端口的问题
    yyancy517
        11
    yyancy517  
       Jan 18, 2024
    我昨天也遇到了, 晚上回去试试 github 给的方案
    BaseException
        12
    BaseException  
       Jan 18, 2024   ❤️ 1
    443 clone, 写 C:\Users\xxx\.ssh\config 文件,这样更好用。

    借楼宣传我写的这篇文章了

    [2022.03] GitHub 加速终极教程 https://hellodk.cn/post/975
    yyancy517
        13
    yyancy517  
       Jan 18, 2024
    为什么回复不了
    yyancy517
        14
    yyancy517  
       Jan 18, 2024   ❤️ 1
    @BaseException #12 好文章, 总结的不错. 晚上我回去试试看行不行
    uncat
        15
    uncat  
       Jan 18, 2024   ❤️ 2
    如果你有一台非中国大陆地区的服务器,假设信息如下:

    地址是:1.2.3.4
    用户名是:root

    把本地的 SSH 公钥添加到服务器上,然后在本地 ~/.ssh/config 内添加:

    Host github.com gitlab.com
    ProxyJump [email protected]

    即可(所有平台都可以,包括 Windows ,Windows 在 PowerShell 内操作)

    不用依赖任何本地工具(比如 netcat)
    uncat
        16
    uncat  
       Jan 18, 2024
    git 协议实际上是基于 SSH 的,上面的配置,是基于 1.2.3.4 进行 SSH 流量中专( ProxyJump )的意思。
    licoycn
        17
    licoycn  
       Jan 18, 2024
    直接同步一下 github 的 hosts ,就可以了,简单粗暴: https://github.com/Licoy/fetch-github-hosts
    wdssmq
        18
    wdssmq  
       Jan 18, 2024
    现在还好,但是去年大半年时间内也是连不上。。让 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 楼的方式万一下次遇上感觉也可以试下。。
    pkoukk
        19
    pkoukk  
       Jan 18, 2024
    @uncat #15 都有代理服务器了,为啥不直接搭个梯子呢
    uncat
        20
    uncat  
       Jan 18, 2024
    @pkoukk 减少复杂度。服务器不需要安装任何工具(出厂默认有 SSH ),服务器添加一行配置,本地需添加两行配置即可。
    codelover612
        21
    codelover612  
       Jan 18, 2024 via iPhone
    我也是,梯子解决
    equationzhao
        22
    equationzhao  
       Jan 18, 2024
    demonchang
        23
    demonchang  
       Jan 18, 2024
    我是改 hosts 140.82.112.3 github.com
    magicZ
        24
    magicZ  
       Jan 18, 2024
    @horizon nice ,可行
    susheng
        25
    susheng  
       Jan 20, 2024
    @demonchang 这个可行,问下 ip 怎么找的?
    demonchang
        26
    demonchang  
       Jan 22, 2024
    @susheng 也是网上搜的
    GodVan
        27
    GodVan  
       Jan 22, 2024
    6 ,lz 的方法可用!
    xinshoushanglu
        28
    xinshoushanglu  
       Jan 26, 2024
    太蛋疼了,github 突然改了这个,我挂代理 也是 git 命令全部不通
    xinshoushanglu
        29
    xinshoushanglu  
       Jan 26, 2024
    先本地加 hosts 的 github 解析记录了,太蛋疼了,挂代理 ssh git 都不行
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3248 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 70ms · UTC 13:49 · PVG 21:49 · LAX 06:49 · JFK 09:49
    ♥ Do have faith in what you're doing.