# VS Code Remote SSH Connection Failed

You're trying to connect to a remote server through VS Code's Remote SSH extension, but you keep getting cryptic errors like "Could not establish connection to X" or "Permission denied (publickey)". The connection hangs indefinitely, or fails immediately with no clear reason.

Common Error Messages

You'll typically see one of these patterns:

bash
[error] Could not establish connection to "myserver"
[error] Permission denied (publickey,password)
[error] Host key verification failed
[error] Connection timed out
[error] Process tried to write something to stderr but failed

Each error points to a different root cause. Let's diagnose and fix them systematically.

Step 1: Test Basic SSH Connectivity

Before diving into VS Code settings, verify SSH works outside of VS Code:

bash
ssh username@hostname -p 22

If this fails, the problem isn't VS Code. Fix your SSH configuration first. If it works, VS Code has a configuration issue.

Step 2: Check SSH Config File

VS Code Remote SSH reads your ~/.ssh/config file. A misconfigured entry causes failures:

bash
Host myserver
    HostName 192.168.1.100
    User myuser
    Port 22
    IdentityFile ~/.ssh/id_rsa

Common mistakes:

  • Wrong IdentityFile path: Use the full path to your private key
  • Missing User: VS Code needs the username specified
  • Incorrect indentation: Use spaces, not tabs, and be consistent

Run this to check for config syntax errors: ``bash ssh -G myserver | head -10

This shows what SSH will actually use for that host.

Step 3: Fix Host Key Verification Issues

If you see "Host key verification failed", the server's fingerprint changed or isn't in your known_hosts:

```bash # Remove old entry ssh-keygen -R hostname

# Reconnect to accept new key ssh username@hostname ```

For VS Code specifically, you may need to accept the key in the terminal first before Remote SSH will work.

Step 4: Resolve Permission Denied Errors

Authentication failures have several causes:

Wrong key permissions: ``bash chmod 700 ~/.ssh chmod 600 ~/.ssh/id_rsa chmod 644 ~/.ssh/id_rsa.pub

Wrong key being used: ``bash # Check which key SSH is trying ssh -v username@hostname 2>&1 | grep "identity file"

Agent not running (for keychain): ``bash # Start SSH agent eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_rsa

Step 5: Fix Server-Side Issues

The remote server might be the problem:

Check if VS Code server is installed: ``bash ls -la ~/.vscode-server/

Clean up corrupted server files: ``bash rm -rf ~/.vscode-server/bin/* rm -rf ~/.vscode-server/extensions

On the next connection, VS Code will reinstall the server components.

Check disk space: ``bash df -h ~

A full disk prevents VS Code server from extracting.

Step 6: Configure Jump Hosts Properly

If you connect through a bastion host, your config needs ProxyJump:

``` Host bastion HostName bastion.example.com User jumpuser IdentityFile ~/.ssh/id_rsa

Host target-server HostName 10.0.0.5 User targetuser ProxyJump bastion IdentityFile ~/.ssh/id_rsa ```

VS Code handles ProxyJump automatically when configured correctly.

Step 7: Enable Verbose Logging

When nothing obvious works, enable detailed logging:

In VS Code settings (settings.json): ``json { "remote.SSH.logLevel": "trace", "remote.SSH.showLoginTerminal": true }

Then check the Output panel, select "Remote - SSH" from dropdown. Look for:

bash
[trace] Running SSH command: ssh -T -D randomport hostname
[trace] Got response: ...

The trace output shows exactly what command VS Code is running and where it fails.

Step 8: Fix Platform-Specific Issues

Windows-specific:

If you're using the built-in OpenSSH client on Windows, ensure it's in your PATH: ``powershell where ssh

If using Git for Windows SSH: ``json // settings.json { "remote.SSH.path": "C:\\Program Files\\Git\\usr\\bin\\ssh.exe" }

macOS-specific:

Keychain integration can interfere: ``bash # Remove key from keychain, re-add ssh-add --apple-use-keychain ~/.ssh/id_rsa

Verification

  1. 1.Test the connection:
  2. 2.Open VS Code
  3. 3.Press F1 → "Remote-SSH: Connect to Host"
  4. 4.Select your configured host
  5. 5.Wait for "Installing VS Code Server" message
  6. 6.Open a terminal in the remote window and verify with uname -a

Quick Reference

ErrorLikely CauseFix
Permission deniedWrong key/permissionsFix key permissions, specify IdentityFile
Host key verification failedServer key changedRemove old key, reconnect
Connection timed outFirewall/networkCheck port, try different network
Could not establish connectionConfig errorVerify SSH config syntax

Remote SSH problems usually stem from SSH configuration issues rather than VS Code itself. Test basic SSH connectivity first, then work through VS Code-specific settings.