假设远程监听 8888 端口, 本地监听 7888 端口
可以通过 ssh 本身的支持:

1
ssh -p 443 -R 8888:localhost:7888 username@hostname

或者通过 vscode 的 ssh 配置文件

1
2
3
4
5
Host test2
HostName test2
Port 443
User root
RemoteForward 8888 localhost:7888

此外还可以设置一下别名

1
2
alias proxy='export http_proxy=localhost:8888;export https_proxy=localhost:8888;export HTTP_PROXY=localhost:8888;export HTTPS_PROXY=localhost:8888'
alias unproxy='unset http_proxy;unset https_proxy;unset HTTP_PROXY;unset HTTPS_PROXY'

如果机器需要跳板连接而不能直连, 则需要修改一下ssh参数. 例如通过host2当跳板连接到host1:
ssh -i ~/.ssh/id_rsa -R 7888:localhost:7888  user@host1 -o ProxyCommand="ssh -W %h:%p user@host2 -p 443"
如果连不上可能是ssh版本问题
ssh -o PubkeyAcceptedAlgorithms=+ssh-rsa admin@10.194.68.198 -o ProxyCommand="ssh -W %h:%p root@11.91.164.144"