文章

命令使用vscode代理

命令使用vscode代理

1) 本地 SSH 配置(RemoteForward 7777→本地7777)

在本地 ~/.ssh/config(Windows 通常 C:\Users\<你>\.ssh\config)写:

Host tuser1
  HostName <远端IP或域名>
  User yingjie
  RemoteForward 7777 127.0.0.1:7777

重连 VSCode Remote-SSH。

2) 远端临时使用(单次 / 当前会话)

1
2
3
4
5
6
7
8
export http_proxy="http://127.0.0.1:7777"
export https_proxy="http://127.0.0.1:7777"

sudo apt -o Acquire::http::Proxy="http://127.0.0.1:7777" \
         -o Acquire::https::Proxy="http://127.0.0.1:7777" update

sudo apt -o Acquire::http::Proxy="http://127.0.0.1:7777" \
         -o Acquire::https::Proxy="http://127.0.0.1:7777" install -y multitail

这仍然是“本次命令/当前会话”生效。

3) 确认远端 7777 没被占用(建议先跑)

1
ss -lntp | grep ':7777' || echo "7777 free"

如果看到已有程序占着 7777,那就换一个远端端口(比如 17777)最省事。

4) 想让 apt 以后都默认走代理(持久化,可选)

1
2
3
4
sudo tee /etc/apt/apt.conf.d/95proxy >/dev/null <<'EOF'
Acquire::http::Proxy "http://127.0.0.1:7777";
Acquire::https::Proxy "http://127.0.0.1:7777";
EOF

取消:

1
sudo rm -f /etc/apt/apt.conf.d/95proxy
本文由作者按照 CC BY 4.0 进行授权