Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect over a proxy #117

Closed
lars18th opened this issue May 4, 2019 · 14 comments
Closed

Connect over a proxy #117

lars18th opened this issue May 4, 2019 · 14 comments
Assignees

Comments

@lars18th
Copy link

lars18th commented May 4, 2019

Hi,

The native SSH client, that uses this project, doesn't have support for connecting through a PROXY.

However, until native support will be added... here a "tip" for you:

  • Insert in your .ssh/config file:
Host myhost
    HostName myhost-address
    ProxyCommand ncat.exe --proxy-type socks4 --proxy <proxy-addr>:1080 %h %p

And that's all! Then you can connect to your dev host over a proxy (or over another SSH session without using the native Jump functionality).

I hope you like it! 😉

@kieferrm
Copy link
Member

kieferrm commented May 4, 2019

@lars18th, can you elaborate on

The native SSH client, that uses this project, doesn't have support for connecting through a PROXY.

ProxyCommand and ProxyJump are the standard way to setup jump boxes in ssh.

@kieferrm kieferrm self-assigned this May 4, 2019
@lars18th
Copy link
Author

lars18th commented May 5, 2019

ProxyCommand and ProxyJump are the standard way to setup jump boxes in ssh.

Hi, I know it! However, note that Windows doesn't have ANY native tool to execute as the ProxyCommand. So for this reason no native solution exists.

In any case my proposal of using ncat.exe works. Perhaps the Microsoft group will like to include it as native.

@juztinzhu
Copy link

@lars18th, can you elaborate on

The native SSH client, that uses this project, doesn't have support for connecting through a PROXY.

ProxyCommand and ProxyJump are the standard way to setup jump boxes in ssh.
Hi kieferrm,
Is ProxyJump even supported by vscode-remote? I tried but failed quickly with a "unreachable or not Linux x86_64". But ssh client works fine with proxyjump in cmd(win10).

@lars18th
Copy link
Author

@lars18th, can you elaborate on

Yes.

  • Current Remote-SSH plugin uses the "native" Win32-OpenSSH SSH Client.
  • With this client, the ONLY solution to connect to the target machine using a PROXY (HTTP or SOCKS4) it's using the parameter ProxyComand in the .ssh/config file.
  • In the WINDOWS PLATFORM to use the ProxyCommand you need an EXTERNAL TOOL, as Microsoft doesn't provide any native helper tool to work with the ProxyCommand.

So, two solutions can be possible:

  1. Or the Microsoft people will expand the Win32-OpenSSH Client with native support of proxies.
  2. Or they provide a tool similar to ncat.exe or connect.exe (or distribute them with the package Win32-OpenSSH).

The main problem is that many developers connect to the target server using SOCKS or HTTP proxies.

I hope it's more clear now. 😉
Regards.

@juztinzhu
Copy link

@lars18th, can you elaborate on

Yes.

  • Current Remote-SSH plugin uses the "native" Win32-OpenSSH SSH Client.
  • With this client, the ONLY solution to connect to the target machine using a PROXY (HTTP or SOCKS4) it's using the parameter ProxyComand in the .ssh/config file.
  • In the WINDOWS PLATFORM to use the ProxyCommand you need an EXTERNAL TOOL, as Microsoft doesn't provide any native helper tool to work with the ProxyCommand.

So, two solutions can be possible:

  1. Or the Microsoft people will expand the Win32-OpenSSH Client with native support of proxies.
  2. Or they provide a tool similar to ncat.exe or connect.exe (or distribute them with the package Win32-OpenSSH).

The main problem is that many developers connect to the target server using SOCKS or HTTP proxies.

I hope it's more clear now. 😉
Regards.

There is a know bug of win32-openssh when use parameter ProxyJump, see: https://github.com/PowerShell/Win32-OpenSSH/issues/1172
there is a PRIVATE fix for this bug, it works fine for a separate ssh process, but when it is called by vscode-remote, still not working. Guess it is a vscode-remote problem.

for the other param ProxyCommand, ssh works fine also, yet still vscode-remote is not working.
either way vscode-remote keeps telling "Can't connect to xx: unreachable or not Linux x86_64 (Thus no job control in this shell.)"

@lars18th
Copy link
Author

Hi @juztinzhu ,

There is a know bug of win32-openssh when use parameter ProxyJump, see: https://github.com/PowerShell/Win32-OpenSSH/issues/1172
there is a PRIVATE fix for this bug, it works fine for a separate ssh process, but when it is called by vscode-remote, still not working. Guess it is a vscode-remote problem.

I don't understand your comment. Please, take note that:

  • Connecting over a PROXY isn't related in any sense to JUMP functionality. The first one it's to use one TCP proxy, over HTTP or SOCKS protocols, to reach the listening TCP port of the remote SSH server. In this case the PROXY is fully transparent. In the case of the JUMP functionality the client stablishes one SSH session to one intermediate SSH server (called the PROXY, but in a different sense), and from this intermediate server it stablishes another SSH session to the final server. The trick in this case is that the connection is encrypted end-to-end and the intermediate server can't intercept the traffic.

for the other param ProxyCommand, ssh works fine also, yet still vscode-remote is not working.
either way vscode-remote keeps telling "Can't connect to xx: unreachable or not Linux x86_64 (Thus no job control in this shell.)"

Regards.

@juztinzhu
Copy link

@lars18th Hi, sorry I confused you. I was thinking that if you had noticed the problem of vscode-remote it self, but clearly you have mentioned it in another post, which I just saw. Please ignore it.

@badscrew
Copy link

badscrew commented Oct 29, 2019

Hello,
I have slightly different configuration that works for me in both Powershell and VSCode ssh remote over http proxy, it uses connect.exe and ssh.exe from git for windows distribution:

(My windows is the Windows 10 Pro 1809)

  1. I have Git for Windows installed in c:\Git\
  2. My system path has c:\Git\usr\bin directory appearing before the %SystemRoot%\system32 in order to have ssh.exe from Git tools as default instead of the ssh.exe delivered by windows that doesn't understand ProxyCommand
  3. in %USERPROFILE%\.ssh\config I have this as typical entry (sanitized)
Host badscrew_web
  User badscrew
  Port 22
  Hostname 123.123.123.123
  IdentityFile "c:\Users\badscrew\mykeys\ssh\id_rsa"
  TCPKeepAlive yes
  IdentitiesOnly yes
  ProxyCommand "c:\Git\mingw64\bin\connect.exe" -H myproxy.mycompany.com:80 %h %p

This works in both powershell command line (ssh badscrew_web) and in VSCode (RemoteSSH - Connect to Host... > badscrew_web).

@anuoua
Copy link

anuoua commented Feb 26, 2020

@badscrew it works!

@imaemo
Copy link

imaemo commented Mar 1, 2020

@badscrew , thanks, I checked, socks proxy also works.
ProxyCommand "C:\Program Files\Git\mingw64\bin\connect.exe" -H 127.0.0.1:1080 %h %p

@ksurl
Copy link

ksurl commented Mar 23, 2020

@imaemo

ProxyCommand "C:\Program Files\Git\mingw64\bin\connect.exe" -H 127.0.0.1:1080 %h %p

does this mean you need to have socks proxy connected in cmd before you connect via vs code remote ssh?

edit: nevermind I got it to work with ProxyCommand ssh -W %h:%p proxy-hostname as mentioned in https://github.com/microsoft/vscode-remote-release/issues/18#issuecomment-497653207

@bamurtaugh
Copy link
Member

Thanks for the discussion here! Upon reviewing this thread, it looks like there are solutions listed, and this isn't quite an issue or feature request lying with Remote - SSH specifically? If folks agree, I'll go ahead and close the issue.

@anuoua
Copy link

anuoua commented Oct 19, 2020

I think the path of connect.exe need escape
ProxyCommand C:\\Program\ Files\\Git\\mingw64\\bin\\connect.exe -H 127.0.0.1:8080 %h %p it works

@bamurtaugh
Copy link
Member

Based on the above, going to close out this thread, but please let me know if there are any other Remote - SSH related inquiries here. Thank you!

@github-actions github-actions bot locked and limited conversation to collaborators Dec 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants