VS Code Remote - SSH fails to set up the dynamic port forward
Failed to set up socket for dynamic port forward to remote port: connect ECONNREFUSEDShort 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.
Fix it fast
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 Log2Match what you see, then jump to its fix
- 1
open failed: administratively prohibited: open failedsshd forbids TCP forwardingFix - 2
The VS Code Server failed to startA stale or half-installed VS Code Server on the hostFix - 3
The connection hangs or fails at the very start, before any server install output.The local SSH server setting hangs or breaks the connectionFix - 4
Errors begin only after you enabled Remote.SSH: Remote Server Listen On Socket.Unix-socket mode is on and the host does not allow itFix
- 1
What does the error look like?
Failed to set up socket for dynamic port forward to remote port: connect ECONNREFUSEDopen failed: administratively prohibited: open failedThe 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 sshd3Verify
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
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 grep2Fix
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-server3Verify
Connect again. VS Code downloads the server fresh and the log ends without ECONNREFUSED.
ls $HOME/.vscode-serverConfirmed by code.visualstudio.com
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.useLocalServer2Fix
Set it to false in your user settings and reconnect.
// settings.json
"remote.SSH.useLocalServer": false3Verify
Reconnect and confirm the log no longer stops at the start.
# Command Palette (F1): Remote-SSH: Show LogConfirmed by code.visualstudio.com
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 sshd3Verify
Reconnect from VS Code.
# Command Palette (F1): Remote-SSH: Connect to Host...Confirmed by code.visualstudio.com
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
Security
SSH refuses your key and ends with Permission denied (publickey)
user@203.0.113.10: Permission denied (publickey,password).
The server accepted the connection but found no key it would take.
5 causes, each with a fixSecurity
AuthenticationException: your certificate validation callback returned false
System.Security.Authentication.AuthenticationException
This message means a validation callback was installed, yours or one a library added, and it returned false.
3 causes, each with a fixSecurity
SSH to an EC2 instance fails with Permission denied (publickey,gssapi-keyex,gssapi-with-mic)
ec2-user@ec2-203-0-113-25.compute-1.amazonaws.com: Permission denied (publickey).
On EC2 this error almost always means the instance did not accept your key for that user.
3 causes, each with a fixSecurity
gcloud init cannot finish the sign-in step
Enter authorization code
gcloud init signs in through a browser.
3 causes, each with a fixSecurity
A GitHub Actions SSH deploy step cannot log in to the server
ssh: handshake failed: ssh: unable to authenticate
The runner reached your server but the server refused the login.
4 causes, each with a fixSecurity
SSH to GitHub asks to confirm the host, or hangs on that prompt
ED25519 key fingerprint is SHA256:
SSH has never seen github.com from this machine, so it asks you to trust the server key.
2 causes, each with a fix