Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

VS Code Remote - SSH fails to set up the dynamic port forward

ErrorFailed to set up socket for dynamic port forward to remote port: connect ECONNREFUSED

Short answer

The connection is made, but VS Code cannot open its tunnel to the VS Code Server on the host. Open the Remote - SSH output log. If it says administratively prohibited, enable TCP forwarding in sshd. Otherwise kill the stale server, turn off the local server option, or allow stream-local forwarding.

  • Applies to VS Code Remote - SSH, OpenSSH server 9, Raspberry Pi OS, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open the Output panel, choose Remote - SSH from the drop-down and read the lines just before the ECONNREFUSED. They tell you which cause applies.

    # Command Palette (F1): Remote-SSH: Show Log
  2. 2Match what you see, then jump to its fix

    1. 1open failed: administratively prohibited: open failedsshd forbids TCP forwardingFix
    2. 2The VS Code Server failed to startA stale or half-installed VS Code Server on the hostFix
    3. 3The connection hangs or fails at the very start, before any server install output.The local SSH server setting hangs or breaks the connectionFix
    4. 4Errors begin only after you enabled Remote.SSH: Remote Server Listen On Socket.Unix-socket mode is on and the host does not allow itFix

What does the error look like?

  • Failed to set up socket for dynamic port forward to remote port: connect ECONNREFUSED
  • open failed: administratively prohibited: open failed
  • The VS Code Server failed to start

Cause 1 of 4

sshd forbids TCP forwarding

1Check

Search the daemon config on the host, including any drop-in files, for the setting.

sudo grep -ri allowtcpforwarding /etc/ssh/

2Fix

Allow TCP forwarding in the daemon config on the host, then restart sshd.

# /etc/ssh/sshd_config
AllowTcpForwarding yes

sudo systemctl restart sshd

3Verify

Reconnect from VS Code and watch the Remote - SSH log reach the connected state.

# Command Palette (F1): Remote-SSH: Connect to Host...

Confirmed by code.visualstudio.com

Did this fix it?

Cause 2 of 4

A stale or half-installed VS Code Server on the host

1Check

A server process left from an earlier session, or a broken install folder, can answer nothing on the port VS Code expects.

ps aux | grep vscode-server | grep $USER | grep -v grep

2Fix

Run Remote-SSH: Kill VS Code Server on Host from the Command Palette. If that does not help, remove the install folder by hand and let VS Code reinstall it.

kill -9 $(ps aux | grep vscode-server | grep $USER | grep -v grep | awk '{print $2}')
rm -rf $HOME/.vscode-server

3Verify

Connect again. VS Code downloads the server fresh and the log ends without ECONNREFUSED.

ls $HOME/.vscode-server

Confirmed by code.visualstudio.com

Did this fix it?

Cause 3 of 4

The local SSH server setting hangs or breaks the connection

1Check

VS Code can use a local helper process for the connection. The troubleshooting page lists turning it off as the fix when connections hang or fail.

# Settings (JSON): look for remote.SSH.useLocalServer

2Fix

Set it to false in your user settings and reconnect.

// settings.json
"remote.SSH.useLocalServer": false

3Verify

Reconnect and confirm the log no longer stops at the start.

# Command Palette (F1): Remote-SSH: Show Log

Confirmed by code.visualstudio.com

Did this fix it?

Cause 4 of 4

Unix-socket mode is on and the host does not allow it

1Check

That setting makes the server listen on a Unix socket on Linux and macOS hosts, which needs stream-local forwarding in sshd.

sudo grep -ri allowstreamlocalforwarding /etc/ssh/

2Fix

Add AllowStreamLocalForwarding yes to sshd_config on the host and restart sshd, or switch the setting off.

# /etc/ssh/sshd_config
AllowStreamLocalForwarding yes

sudo systemctl restart sshd

3Verify

Reconnect from VS Code.

# Command Palette (F1): Remote-SSH: Connect to Host...

Confirmed by code.visualstudio.com

Did this fix it?

How do I stop it coming back?

  • Keep sshd_config changes in one place and record why TCP forwarding is on.
  • Use Remote-SSH: Kill VS Code Server on Host after interrupted installs or host upgrades.
  • Do not mount /tmp noexec on a host you connect to with VS Code, as the install script cannot run there.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.