Troubleshooting

Debugging VS Code SSH: Fix 3 Common Connection Fails 2025

Tired of VS Code SSH connection fails? Learn to debug and fix the 3 most common errors in 2025: Permission Denied, connection hangs, and config permissions.

A

Alex Miller

Senior DevOps Engineer specializing in cloud infrastructure and developer experience optimization.

7 min read3 views

Why VS Code SSH Fails

Visual Studio Code's Remote - SSH extension is a game-changer for modern development. It lets you use your favorite local editor to seamlessly work on files and run commands on any remote server, from a powerful cloud VM to a Raspberry Pi. The workflow is magical... until it isn't. When that dreaded "Could not establish connection" error appears, it can grind your productivity to a halt.

Don't worry. Most connection failures fall into a few common categories. In this updated 2025 guide, we'll walk through the three most frequent VS Code SSH connection problems and provide clear, step-by-step instructions to fix them. Let's banish these errors and get you back to coding.

The Golden Rule: Test SSH in Your Terminal First

Before you start tearing apart your VS Code settings, perform this one crucial check. Open your local terminal (not the one in VS Code) and try to connect to your server directly:

ssh your_user@your_host

If this command fails, your problem isn't with VS Code—it's with your fundamental SSH setup. You'll need to solve that first. If the command succeeds, but VS Code still fails, then you've successfully isolated the issue to the extension or its configuration. This guide is for you.

Fail #1: Permission Denied (publickey)

This is, by far, the most common error. You try to connect, and VS Code immediately fires back an error containing the phrase Permission denied (publickey). This means your local machine successfully reached the remote server, but the server rejected your authentication attempt.

Common Causes

  • Incorrect SSH Key: Your local SSH client is presenting a key that the server doesn't recognize or trust.
  • SSH Agent Isn't Running or Loaded: The SSH agent, a background helper that holds your decrypted keys, either isn't running or doesn't have your required key loaded into its memory.
  • Wrong Permissions on the Server: The ~/.ssh directory or the ~/.ssh/authorized_keys file on the remote server has incorrect file permissions, causing the server's SSH daemon to ignore them for security reasons.

How to Fix It

Follow these steps in order:

1. Verify Your SSH Config File (~/.ssh/config):

Check your local SSH configuration file to ensure you're telling VS Code to use the correct private key for the host. The IdentityFile directive is key.

Host my-remote-server
  HostName 192.168.1.100
  User myuser
  # Ensure this points to the correct private key
  IdentityFile ~/.ssh/id_rsa_server_key

2. Check Your Local SSH Agent:

The SSH agent caches your keys so you don't have to type your passphrase every time. First, list the keys the agent currently knows about:

ssh-add -l

If you see "The agent has no identities." or your required key is missing, add it:

ssh-add ~/.ssh/id_rsa_server_key

You'll be prompted for your passphrase if it has one. Once added, try connecting in VS Code again.

3. Check Permissions on the Remote Server:

SSH into your server using the terminal. Once connected, run these commands to enforce the strict permissions SSH requires:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
  • chmod 700 ~/.ssh: Ensures only you (the user) can read, write, and execute files in your .ssh directory.
  • chmod 600 ~/.ssh/authorized_keys: Ensures only you can read and write your authorized keys file.

These three checks solve "Permission Denied" errors over 90% of the time.

Fail #2: Connection Hangs or "Could not establish connection"

This error is more subtle. You initiate the connection, and VS Code hangs on a step like "Setting up SSH Host..." or "Opening Remote..." for a long time before timing out with a generic error like Could not establish connection or sometimes a cryptic "process tried to write to a nonexistent pipe."

Common Causes

  • Corrupted VS Code Server Installation: The small server component that VS Code installs on the remote host is in a bad state.
  • Network Issues: A firewall or proxy is preventing the remote host from downloading the VS Code server binary from Microsoft's servers.
  • Interactive Login Scripts: Your server's .bashrc, .zshrc, or .profile script has a command that requires user input (like echo "Welcome!" or a prompt), which breaks the non-interactive script VS Code uses to connect.

How to Fix It

1. Kill and Reinstall the VS Code Server:

VS Code has a built-in command for this. Open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P) and search for:

Remote-SSH: Kill VS Code Server on Host...

Select it, choose the problematic host, and let it run. This will remove the server-side components. The next time you connect, the extension will perform a fresh installation.

2. Manually Delete the .vscode-server Directory:

If the command above doesn't work, SSH into the remote server via terminal and manually delete the directory:

rm -rf ~/.vscode-server

This achieves the same result, forcing a clean reinstall on the next connection attempt.

3. Sanitize Your Remote Login Scripts:

This is a sneaky one. Edit your shell startup files on the server (e.g., ~/.bashrc) and ensure there are no commands that print output or expect input. Any such commands should be wrapped in a check to see if the shell is interactive.

For Bash or Zsh, you can use this check:

# Only run interactive commands if the shell is interactive
if [[ $- == *i* ]]; then
  # Place your echo, neofetch, or other interactive commands here
  echo "Welcome back, myuser!"
fi

This prevents these commands from interfering with VS Code's automated connection script.

Fail #3: "Bad owner or permissions on ~/.ssh/config"

This error is a client-side problem. It happens on your local machine before VS Code even attempts to connect to the server. The SSH client is refusing to use a configuration file that it deems insecure.

The Simple Cause

Your local ~/.ssh/config file has permissions that are too open. For example, it might be writable by other users on your system. SSH sees this as a major security risk—if another user could modify your config, they could redirect your SSH connections to a malicious server. So, it refuses to proceed.

How to Fix It

The fix is to lock down the file's permissions.

For macOS and Linux:

Open your local terminal and run this simple command:

chmod 600 ~/.ssh/config

This sets the permissions so that only your user account can read and write the file, which is exactly what the SSH client wants.

For Windows:

The concept is the same, but the execution is different. Right-click your C:\Users\YourUser\.ssh\config file, go to Properties > Security > Advanced. Ensure that your user account is the owner and is the only user in the list with permissions (Full control is fine). Remove any other users or groups (like "Everyone" or "Administrators") from the list.

Quick Diagnostics: Which Problem Do You Have?

Use this table to quickly identify your issue based on the symptoms.

VS Code SSH Error Comparison
SymptomLikely CauseFix Location
Error message contains "Permission denied (publickey)"Mismatched SSH keys or bad server-side permissions.Both (check local config/agent, then remote authorized_keys permissions).
Connection hangs for a long time then times out.Corrupted VS Code server or an interactive remote login script.Remote Server (delete ~/.vscode-server or edit .bashrc).
Error message contains "Bad permissions on ... config"Local SSH config file is not secure.Local Machine (run chmod 600).

Pro-Tips for Advanced Debugging in 2025

If the common fixes don't work, it's time to dig deeper.

Use the VS Code Output Log

VS Code provides a detailed log for the SSH extension. Go to View > Output (or Ctrl+Shift+U) and select "Remote - SSH" from the dropdown menu. This log contains the full, verbose output of the SSH command VS Code is running and can provide critical clues about where it's failing.

Master Verbose SSH in Terminal

Run your SSH command from the terminal with the verbose flag (-v) to get more insight. For maximum detail, use three (-vvv):

ssh -vvv your_user@your_host

This will print out every step of the connection and authentication process, from reading config files to negotiating ciphers and trying public keys. Compare this with the VS Code log to spot discrepancies.

Conclusion: Get Back to Coding

VS Code SSH connection issues can be a major roadblock, but they are almost always solvable. By working systematically—verifying your base connection, checking permissions, clearing caches, and sanitizing scripts—you can resolve the vast majority of problems. Remember to use the diagnostic tools at your disposal, like the VS Code output log and verbose SSH flags, to pinpoint the root cause.

With these three common failures demystified, you're now equipped to tackle connection problems head-on and maintain a smooth, efficient remote development workflow in 2025 and beyond.