VS code SSH隧道

3

我有关于在 VS Code 中使用 SSH 隧道的问题。我正在使用 Remote - SSH 扩展连接远程机器。我的现有设置是:在 Putty 中创建到下一节点的隧道,以连接服务器。

PUTTY -> someIP -> polaris:22 (tunnel)

Putty 在本地主机上创建到 polaris 的隧道,并将其映射到 localhost:4000。在此之后,我可以通过 VS Code 与远程 SSH 连接到 localhost:4000 并正常工作。

这个扩展中是否有直接创建 SSH 隧道的功能而不使用 Putty? :)


你有没有想过如何通过SSH隧道从A->B->C实现VSCode远程连接?我现在也在研究这个问题。 - El Dude
2个回答

1

我从https://superuser.com/questions/1528212/vscode-ssh-with-multiple-hops得到了答案。

在我的情况下,我正在使用Windows上的VSCode连接到组织网络中的多台Linux机器以及通过SSH隧道从组织外部连接。

在我的配置文件remoteSsh.configFile中,我有以下配置。

Host machineName1 (to connect from inside organization)
  HostName [machineName1.organization_internal_extension]
  Port [portNumber for ssh]
  User [Username]
  IdentifyFile [local path to ssh key]
  ForwardAgent yes
  ForwardX11 yes
  ForwardX11Trusted yes

Host machineName2 (to connect from inside organization)
  HostName [machineName2.organization_internal_extension]
  Port [portNumber for ssh]
  User [Username]
  IdentifyFile [local path to ssh key]
  ForwardAgent yes
  ForwardX11 yes
  ForwardX11Trusted yes

Host tunne_machineName1 (to connect from outside organization)
  HostName [machineName1.organization_internal_extension]
  Port [portNumber for ssh]
  User [Username]
  IdentifyFile [local path to ssh key]
  ForwardAgent yes
  ForwardX11 yes
  ForwardX11Trusted yes
  ProxyJump machine_tunnel

Host tunne_machineName2 (to connect from outside organization)
  HostName [machineName2.organization_internal_extension]
  Port [portNumber for ssh]
  User [Username]
  IdentifyFile [local path to ssh key]
  ForwardAgent yes
  ForwardX11 yes
  ForwardX11Trusted yes
  ProxyJump machine_tunnel

Host machine_tunnel( machine to jump)
  HostName [machineName.organization_internal_extension]
  Port [portNumber for ssh on tunnel machine]
  User [Username]
  IdentifyFile [local path to ssh key]
  ForwardAgent yes
  ForwardX11 yes
  ForwardX11Trusted yes


X11转发不是必需的。

希望这可以帮到你。


-1
将以下信息放入您本地机器的/.ssh/config文件中:
Host [1]
    HostName [2]
    User [3]
    Port [4]

将[1]、[2]、[3]和[4]替换为您喜欢的主机名主机的IP地址您登录远程服务器的用户名分配给您的本地主机端口

例如,

Host VM1000
    HostName 123.45.678.9
    User root
    Port 4000

然后您只需在 VS Code 中单击 Remote Explorer 图标,然后单击 VM1000 条目,即可将本地计算机连接到远程服务器。

希望这能解决您的连接问题。


他正在寻找一种进行SSH隧道连接的方法,而不仅仅是单个SSH连接。 - Fabio Magarelli

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接