ryougifujino
V2EX  ›  问与答

Mac 上如何 git clone ssh 协议的时候也走代理?

  •  1
     
  •   ryougifujino · Feb 25, 2020 · 5477 views
    This topic created in 2297 days ago, the information mentioned may be changed or developed.

    目前通过配置

    git config --global http.proxy 和

    git config --global https.proxy

    使得 http/https 协议 clone 时是走代理了,但是 ssh 还是直连。该如何设置呢?

    12 replies    2020-02-27 16:57:58 +08:00
    Jaosn
        1
    Jaosn  
       Feb 25, 2020
    export https_proxy=http://127.0.0.1:8888;export http_proxy=http://127.0.0.1:8888;export all_proxy=socks5://127.0.0.1:8889
    hguandl
        2
    hguandl  
       Feb 25, 2020
    .ssh/config:

    Host github.com
    ProxyCommand=nc -X 5 -x 127.0.0.1:1080 %h %p

    如果全部都想走代理就把 Host github.com 换成 Host *

    详见 https://gist.github.com/bynil/2126e374db8495fe33de2cbc543149ae
    ryougifujino
        3
    ryougifujino  
    OP
       Feb 25, 2020
    @hguandl #2 你好,首先谢谢你的回答。但我配置之后为什么就提示这个了呢?没配置之前是可以的。
    nc: read failed (0/3): Broken pipe
    ssh_exchange_identification: Connection closed by remote host
    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.
    ryougifujino
        4
    ryougifujino  
    OP
       Feb 25, 2020
    @hguandl #2 可以了,再次感谢。ProxyCommand=nc -X 5 -x 127.0.0.1:1080 %h %p,这句话实际上是指向的 socks5,而我 socks5 的端口是 1081,改了就可以了。
    statement
        5
    statement  
       Feb 25, 2020 via iPhone
    你给终端配一个代理不就行了
    Smilencer
        6
    Smilencer  
       Feb 25, 2020
    # proxy
    export http_proxy=socks5://127.0.0.1:10802
    export https_proxy=$http_proxy
    CEBBCAT
        7
    CEBBCAT  
       Feb 25, 2020
    这个问题不简单,但也不是搜不到。
    cat .ssh/config
    Host github.com
    HostName github.com
    User git
    # 走 HTTP 代理
    # ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=8080
    # 走 socks5 代理(如 Shadowsocks )
    ProxyCommand nc -v -x 127.0.0.1:1080 %h %p
    xiri
        8
    xiri  
       Feb 25, 2020
    你需要配置 ssh 代理
    snowy0723
        9
    snowy0723  
       Feb 26, 2020 via Android
    再提供一个方法,用 proxychains.
    Kobayashi
        10
    Kobayashi  
       Feb 26, 2020 via Android
    Mellow,Surge 直接 TUN 无感知拦截。更狠的还有 Proxifier 内核模块拦截,代理。
    hive
        11
    hive  
       Feb 27, 2020
    @CEBBCAT #7
    ProxyCommand nc -v -x 127.0.0.1:1080 %h %p
    ProxyCommand=nc -X 5 -x 127.0.0.1:1080 %h %p

    -v 和 -X 5 的区别是什么呢
    hive
        12
    hive  
       Feb 27, 2020
    @lbyo #11 https://man.openbsd.org/nc.1#SYNOPSIS
    找到 config 文档了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3119 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 67ms · UTC 14:38 · PVG 22:38 · LAX 07:38 · JFK 10:38
    ♥ Do have faith in what you're doing.