16

I am trying to connect my VSCode to a raspberry pi4 via the Remote - SSH extension by Microsoft, but I get a ECONNREFUSED error every time. The error log:

[14:49:20.954] Starting forwarding server. localPort 58139 -> socksPort 58137 -> remotePort 44131
[14:49:20.954] Forwarding server listening on 58139
[14:49:20.954] Waiting for ssh tunnel to be ready
[14:49:20.955] [Forwarding server 58139] Got connection 0
[14:49:20.956] Tunneled 44131 to local port 58139
[14:49:20.957] Resolved "ssh-remote+192.168.42.1" to "127.0.0.1:58139"
[14:49:20.958] Failed to set up socket for dynamic port forward to remote port 44131: connect ECONNREFUSED 127.0.0.1:58137. Is the remote port correct?
[14:49:20.965] ------




[14:49:20.980] [Forwarding server 58139] Got connection 1
[14:49:20.981] Failed to set up socket for dynamic port forward to remote port 44131: connect ECONNREFUSED 127.0.0.1:58137. Is the remote port correct?

VScode will successfully ssh into the pi and install the vscode server, but it fails shortly afterward.

This is the line I fed VSCode to create the SSH host:

ssh -i ~/.ssh/rsa_file [email protected]

The pi's ssh file has:

Port 22
AllowTcpForwarding yes
AllowAgentForwarding yes
AllowStreamLocalForwarding yes
DisableForwarding no
TCPKeepAlive yes

My local config:

Host vscode_to_pi
  HostName 192.168.42.1
  IdentityFile ~/.ssh/rsa_file
  User pi
  ForwardAgent yes
  ForwardX11 yes
  PubKeyAcceptedKeyTypes=+ssh-rsa
  HostKeyAlgorithms=+ssh-rsa
  StrictHostKeyChecking=no

I have tried:

  1. https://github.com/microsoft/vscode-remote-release/issues/6447
  2. https://github.com/microsoft/vscode-remote-release/issues/4182
  3. SSH Port forwarding failed when trying to connect to remote database via SSH
  4. VSCode Remote SSH Connection Failed
  5. Killing the VSCode server on host, reinstalling
  6. Restarting VSCode

Some notes:

  1. I am connecting to the pi via the pi's wifi dongle. The pi does not permit internet access while connected to it, but the pi is able to install the VSCode server just fine.
  2. In the extension settings, Enable Agent Forwarding and Enable Dynamic Forwarding are on.
  3. Local Server Download is off. I can't download anything if I'm connected to the pi, anyway.
  4. Pi4 debian version is 11.3
  5. VSCode version is 1.76.2
  6. Remote - ssh extension version is v0.101.2023032415
2
  • @SteffenUllrich I don't know much about TCP, so I'm trying to cover my bases. I have never done this before. How would I go about ensuring the TCP service will listen to the port? Commented Mar 24, 2023 at 20:49
  • I have (almost) the same problem, but in the error message I get: "Socket closed" instead of the ECONNREFUSED. This sounds like a networking issue, but I've tried adding so many iptables rules and none of them seem to work for me. My suspicion is that (in my case) kubernetes sets up some firewall rules automatically and they have higher precedence, but I can't figure them out correctly Commented May 5, 2023 at 7:48

7 Answers 7

45

I had the same case, and I solved it by deleting the ~/.ssh/known_hosts file on the host that I was attempting to connect from.

My OS: macOS Monterey

Sign up to request clarification or add additional context in comments.

8 Comments

This finally solved it for me.
Delete on host or server?
@Ynjxsjmh I deleted it on the host and it solved it for me
WTF. Why? Also solved it for me!
Solved it for me, you're a legend
|
3

Just a reminder, have you systemctl restart sshd after changing /etc/ssh/sshd_config of the remote server. After setting AllowTcpForwarding and AllowTcpForwarding to true and restart the sshd, the problem disappered in my env.

Comments

3

For me, the solution was to add the following lines to the SSH config (be careful using this, as it is highly insecure; make sure to specify it only for explicit domains, not for the entire SSH config):

UserKnownHostsFile /dev/null
StrictHostKeyChecking no

You could read more about the UserKnownHostsFile option there: https://askubuntu.com/a/385187/1031699

3 Comments

This is not a good idea. It is disabling a security feature, and doing so for all ssh connections, not just those made by VS Code. It's fine to do if that's what you want, but don't recommend it without those caveats.
@GlennWillen thanks for the suggestion! I edited my answer to add the note about insecurities. In my case, I was sure it was a secure domain and environment, and I configured it only for the VSCode-specific machine connection.
This solution works for me
2

The recent VS Code update somehow breaks Remote SSH. Reverting to the previous version of VS Code worked for me. Here's how to do it.

  1. Go to https://code.visualstudio.com/updates/
  2. Copy link to your respective download (in my case Windows: System).
  3. Go to a new tab. Paste your link and edit it before you hit enter. https://update.code.visualstudio.com/1.83.1/win32-x64/stable becomes https://update.code.visualstudio.com/1.83.0/win32-x64/stable

Installing the old version did not remove any configs or extensions I had before.

Comments

0

Unsure of the specificity to the problem but believe its a network issue. I was having the same issues, connected with a different network and it was solved.

Comments

0

For me when I used the "Reload Window" action I repeatedly got this error, however closing vs code fully and reopening it solved it.

Comments

-5

I had the same issue and solved it by rebooting my mac laptop.

2 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
This worked for me on 2023 Macbook Pro

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.