VS code SSH tunnel

Viewed 5519

I have question about ssh tunnel in VS code. I am using for connecting to remote machine Remote - SSH extension. My setup now is: putty for connecting to server, in Putty after it is created Tunnel to next point.

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

Putty create tunnel to polaris on localhost:4000. After it, I can use VS code with remote SSH to localhost:4000 and it working fine.

Is in this extension some possibility to create SSH tunnel directly without using putty? :)

2 Answers

I got the answer from https://superuser.com/questions/1528212/vscode-ssh-with-multiple-hops

In my case I'm using VSCode in windows to connect to several linux machines from the organization net and from outside the organization via an ssh tunnel.

In my configuration file remoteSsh.configFile I have the following configuration.

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


The X11 forward is not mandatory.

Hope this helps

Put the following information into your local machine's /.ssh/config:

Host [1]
    HostName [2]
    User [3]
    Port [4]

Substitute [1], [2], [3], and [4] with a host name you prefer, the IP address of the host, the user name you log in the remote server, and the localhost port assigned to you. For example,

Host VM1000
    HostName 123.45.678.9
    User root
    Port 4000

Then you can just click the Remote Explorer icon in VS Code and click the VM1000 entry to connect your local machine to the remote server.

Hope this resolve your connection problem.

Related