V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
PatrickLe
V2EX  ›  SSH

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

  •  
  •   PatrickLe · 13 天前 · 477 次点击
    一个海外的 VPS 被墙了,试着在 surge 里对这个 IP 加上代理,但是不起作用,请问下该怎么解决呢?
    3 条回复    2024-05-06 15:13:34 +08:00
    9136347
        1
    9136347  
       13 天前
    export http_proxy="http://127.0.0.1:1087"
    export https_proxy="http://127.0.0.1:1087"
    vikland
        2
    vikland  
       13 天前
    使用 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  
       13 天前
    方案一:直接把 Surge 的增强模式( Enhanced Mode )
    方案二:就是上面的 ssh config 中添加 ProxyCommand nc -X 5 -x 127.0.0.1:6153
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2172 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 09:47 · PVG 17:47 · LAX 02:47 · JFK 05:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.