不能连外网的机器怎么搭环境?

如何通过SSH建立反向代理

JamzumSum · ·updated 2026年6月21日 · 1 min read
reverse
reverse Photo by @devintavery.

Motivation

许多服务器被限制只能在内网中访问。无论是 conda、pip、docker 还是 apt,无法访问公网都是一个棘手的问题。本文不讨论如何直接解决这类问题,而是介绍如何快速建立一条反向代理通道,从而让服务器借助客户机的网络访问软件源。

工具

唯一的前提是本地机器需要有正在运行的代理。

下文请将 <local_port><remote_port> 替换为实际端口号,将 <REMOTE> 替换为 SSH 配置名或主机名。

  • 本地终端:
    ssh -NR <remote_port>:localhost:<local_port> <REMOTE>
    
  • 远程终端:设置代理即可
    export https_proxy=http://localhost:<remote_port>
    

后记

conda、curl 等工具均支持 https_proxy 的配置。

标签 #Shell
分享
作者
JamzumSum

Open-source developer, major language: Python, C++.

Comments

Hook this up to your favourite commenting platform — Giscus, Disqus, or your own.

Continue reading