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

mac 的 SSH 连接可以套代理吗?

  •  
  •   PatrickLe · May 6, 2024 · 1993 views
    This topic created in 729 days ago, the information mentioned may be changed or developed.
    一个海外的 VPS 被墙了,试着在 surge 里对这个 IP 加上代理,但是不起作用,请问下该怎么解决呢?
    3 replies    2024-05-06 15:13:34 +08:00
    9136347
        1
    9136347  
       May 6, 2024
    export http_proxy="http://127.0.0.1:1087"
    export https_proxy="http://127.0.0.1:1087"
    vikland
        2
    vikland  
       May 6, 2024
    使用 netcat ,brew install netcat
    然后 nc 看一下安装成功没。
    单次连接就
    `ssh -o ProxyCommand="nc -x 127.0.0.1:7897 %h %p" user@remotehost`

    如果每次都想使用代理,就修改~/.ssh/config 文件。
    添加上 ProxyCommand:
    ```shell
    Host remotehost
    ProxyCommand nc -x 127.0.0.1:7897 %h %p
    ```


    附录一个 config 样例:
    ```shell
    # 默认设置,适用于所有主机
    Host *
    # 使用特定的密钥文件
    IdentityFile ~/.ssh/id_rsa
    # 设置连接超时时间(秒)
    ConnectTimeout 10
    # 自动添加新的主机键到用户主机文件
    StrictHostKeyChecking ask
    # 使用代理(假设你有一个运行在本地的 SOCKS5 代理)
    ProxyCommand nc -x 127.0.0.1:7897 %h %p

    # 特定主机的设置
    Host example.com
    # 为这个主机指定不同的用户名
    User myusername
    # 指定这个主机的密钥文件
    IdentityFile ~/.ssh/id_example.com
    # 禁用代理
    ProxyCommand none

    # 使用特定端口的主机
    Host anotherhost
    # 指定连接端口
    Port 2222
    # 指定用户名
    User anotheruser
    # 对于这个主机,不使用代理
    ProxyCommand none
    ```
    Volekingsg
        3
    Volekingsg  
       May 6, 2024
    方案一:直接把 Surge 的增强模式( Enhanced Mode )
    方案二:就是上面的 ssh config 中添加 ProxyCommand nc -X 5 -x 127.0.0.1:6153
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2533 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 05:23 · PVG 13:23 · LAX 22:23 · JFK 01:23
    ♥ Do have faith in what you're doing.