microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.51k stars 28.98k forks source link

SSH fails only in the integrated terminal #229240

Open 3f6a opened 3 weeks ago

3f6a commented 3 weeks ago

I ran into a strange situation where:

ssh remote_host

fails, when run on the VS code integrated terminal, but the same command succeeds on my system (external) terminal. I tried to bisect what was going on with limited knowledge, and I'll attempt to give more details here.

This issue only happens on a wired connection at work, where the network has some corporate restrictions. If I connect on the WiFi, in the same network, the issue does not happen. I then figured that there must be something different in the way network connections (specifically ethernet) are handled within VS code and its integrated terminal, vs. the external terminal. However, I tried running things like env and ifconfig, but I see pretty much identical outputs (up to minor vscode specific differences that I don't think are relevant).

Lastly, my personal machine is on macOS, latest version. The remote is a Linux box within the corporate network.

If anyone with more knowledge has any specific questions, or any illuminating suggestions of what differs in terms of networking between the VS code integrated terminal and the external terminal, I'd be happy to provide more details.

albertosantini commented 3 weeks ago

A few ideas.

Just my two cents.

3f6a commented 3 weeks ago

@albertosantini

Check if the ssh command executed is the same, intending stock MacOS or something else (which ssh).

It is the same, in both cases /usr/bin/ssh.

Debug ssh with -v or -vv or -vvv to see the diffs between ssh VSCode terminal and external terminal

The output of ssh -vvv is exactly the same in both cases.

albertosantini commented 3 weeks ago

It cannot be the same debug session: this is very weird.

It would mean ssh correctly works in both context, vscode terminal and external terminal, doesn't it?

3f6a commented 3 weeks ago

The output of ssh -vvv is exactly the same in both cases.

@albertosantini Sorry this was inaccurate. I meant the same up to the point of failure (No route to host). Here is the output I get from the integrated terminal:

% ssh -vvv REMOTE_HOST
OpenSSH_9.8p1, LibreSSL 3.3.6
debug1: Reading configuration data ~/.ssh/config
debug1: ~/.ssh/config line 77: Applying options for lecuona
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug2: resolve_canonicalize: hostname REMOTE_IP_ADDRESS is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '~/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '~/.ssh/known_hosts2'
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug3: channel_clear_timeouts: clearing
debug3: ssh_connect_direct: entering
debug1: Connecting to REMOTE_IP_ADDRESS [REMOTE_IP_ADDRESS] port 22.
debug3: set_sock_tos: set socket 3 IP_TOS 0x48
debug1: connect to address REMOTE_IP_ADDRESS port 22: No route to host
ssh: connect to host REMOTE_IP_ADDRESS port 22: No route to host

For the external terminal, the same command works with the same output up to the last No route to host messages.

albertosantini commented 3 weeks ago

I am afraid VSCode and its terminal is not the culprit.

See https://superuser.com/questions/1804868/why-doesnt-ssh-work-if-wifi-is-on-while-ethernet-is-connected

Hope that helps. No other ideas here.

3f6a commented 3 weeks ago

Actually, same issue happens with a WiFi connection (and no Ethernet connection). This WiFi is one of the ones provided internally in the corporate network.

So it seems to me that something is different in the way ssh runs within the integrated terminal vs. the external terminal ... what could it be ?

albertosantini commented 3 weeks ago

ssh -vvvv ... Last try and catch the diffs. :)

3f6a commented 3 weeks ago

Like before, no difference, up to the No route to host failure .... (I thought ssh -vvv was the max verbosity possible)

albertosantini commented 3 weeks ago

The terminal itself cannot be involved.

I have been following the idea, for some reason, the enviroment or the setup is different.

Another idea is traceroute, the network path in wifi and ethernet maybe are different or the company set different "filters".

I recap the tests:

Did I understand correctly?

3f6a commented 3 weeks ago

Did I understand correctly?

There are two WiFi networks. On one of them VScode terminal fails, but on the other it works. In all cases, external terminal always works.

ifconfig gives exact same outputs for both. I just tried traceroute and also shows exactly the same output. env shows some differences specific to VS code, that as far as I can see are unrelated.

GreenRockD commented 3 weeks ago

I ran into a strange situation where:

ssh remote_host

fails, when run on the VS code integrated terminal, but the same command succeeds on my system (external) terminal. I tried to bisect what was going on with limited knowledge, and I'll attempt to give more details here.

This issue only happens on a wired connection at work, where the network has some corporate restrictions. If I connect on the WiFi, in the same network, the issue does not happen. I then figured that there must be something different in the way network connections (specifically ethernet) are handled within VS code and its integrated terminal, vs. the external terminal. However, I tried running things like env and ifconfig, but I see pretty much identical outputs (up to minor vscode specific differences that I don't think are relevant).

Lastly, my personal machine is on macOS, latest version. The remote is a Linux box within the corporate network.

If anyone with more knowledge has any specific questions, or any illuminating suggestions of what differs in terms of networking between the VS code integrated terminal and the external terminal, I'd be happy to provide more details.

GreenRockD commented 3 weeks ago

ssh remote_host

albertosantini commented 3 weeks ago

@3f6a When you switch from "wifi ok" to "wifi ko" do you restart VSCode?

teddykoker commented 3 weeks ago

I was having the same issue after updating to MacOS Sequoia. I was unable to use ssh from vscode to any server the same network that I was currently on (with no helpful message other than undefined error 0), but had no issue if I was on a different network, or using a different terminal application. It turns out MacOS Sequoia added a "Local Network" security setting which limits communication between devices on your local network for individual apps. Switching on vscode in Settings > Privacy > Local Network fixed this issue for me, and explains why ssh worked in the default terminal application, and in vscode while on non-local network. Hope this helps!

Edit: see also #228862

3f6a commented 3 weeks ago

@teddykoker Thanks! Indeed the issue surfaced after I updated to macOS Sequoia. I will try this next time I'm at the corporate network!