6

I need to connect via REMOTE-SSH in Visual Studio Code to a machine with ssh but from a specific machine in which I have previously connected through ssh to.

I can connect to the first machine with no problem, the problem is when I am logged in the first machine and I try to connect to the second it doesn't let me. I have been looking but what I can only find is examples showing how to connect only to one machine without passing through an other one.

MarinerZZ
  • 332
  • 1
  • 3
  • 13

2 Answers2

11

Thanks to a partner, I have found a solution and it consists in changing a little bit the config file from ssh

As I am using VS Code in Windows and I wanted not to use netcat I've implemented the next command to create a proxy:

Host <target-machine-name>
HostName <target-machine-ip>
User <user>
ProxyCommand C:\Windows\System32\OpenSSH\ssh.exe -q -x <proxy-machine-name> -W %h:22

Hope it can help someone else with the same issue.

MarinerZZ
  • 332
  • 1
  • 3
  • 13
  • 3
    Worked for me. Config file is in ~\.ssh directory. You may need to specify the user for the "" part of the example, e.g. "user@ipAddress". – Jerry K. Oct 02 '19 at 13:21
  • On linux, almost the same command: `ProxyCommand ssh -q -x -W %h:22` – Anwarvic Jul 27 '22 at 09:12
5

If you are using macOS and want to ssh to machine 1.1.1.1:2222 under socks proxy(127.0.0.1:1080), then you can use the below configuration:

Host 1.1.1.1
    HostName 1.1.1.1
        ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p 
    Port 2222
    User YourName

If you are using http proxy or using Windows(Linux), go to check Connect with SSH through a proxy . Then replace the corresponding ProxyCommand.

Hope this could help you.

Jianing
  • 111
  • 2
  • 4