# Fix VS Code Remote SSH Connection Failed With Key Exchange Error

You try to connect to a remote server using VS Code's Remote - SSH extension, but the connection fails:

bash
Could not establish connection to "remote-server"

The Output panel shows:

bash
SSH ERROR: kex_exchange_identification: Connection closed by remote host

Or:

bash
SSH ERROR: Unable to negotiate with 10.0.1.50 port 22: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1

Or:

bash
SSH ERROR: no matching host key type found. Their offer: ssh-rsa,ssh-dss

These are SSH key exchange negotiation failures between your local SSH client and the remote server.

Problem 1: No Matching Key Exchange Method

Older SSH servers only support deprecated key exchange algorithms. Modern SSH clients (OpenSSH 8.8+) disable these by default for security reasons.

Fix by adding the algorithm to your SSH config (~/.ssh/config):

bash
Host remote-server
    HostName 10.0.1.50
    User deploy
    KexAlgorithms +diffie-hellman-group1-sha1

The + prefix adds the algorithm to the default list rather than replacing it.

Problem 2: No Matching Host Key Type

Similar issue with host key algorithms:

bash
Host legacy-server
    HostName 192.168.1.100
    User admin
    HostKeyAlgorithms +ssh-rsa
    PubkeyAcceptedAlgorithms +ssh-rsa

Problem 3: VS Code Server Installation Failed

Even if SSH connects successfully, VS Code may fail to install its server component on the remote machine:

bash
Installing VS Code Server on the remote...
Failed to install VS Code Server

Check the remote machine:

```bash # Check disk space df -h

# Check VS Code Server directory ls -la ~/.vscode-server/

# Check permissions ls -la ~/.vscode-server/bin/ ```

Common causes: - Insufficient disk space on the remote server - No internet access from the remote server (cannot download VS Code Server) - Firewall blocking the download

Fix by manually downloading and installing:

bash
# On the remote server, get the commit ID from the VS Code local machine
# Then download manually
COMMIT_ID="abc123def456"
wget "https://update.code.visualstudio.com/commit:$COMMIT_ID/server-linux-x64/stable" -O vscode-server.tar.gz
mkdir -p ~/.vscode-server/bin/$COMMIT_ID
tar -xzf vscode-server.tar.gz -C ~/.vscode-server/bin/$COMMIT_ID --strip-components=1

Problem 4: SSH Key Not Accepted

The remote server rejects your SSH key:

bash
Permission denied (publickey,password).

Check which keys are being offered:

bash
ssh -v remote-server 2>&1 | grep "Offering public key"

If your key is not listed, add it to the SSH agent:

bash
ssh-add ~/.ssh/id_ed25519

Or specify it in SSH config:

bash
Host remote-server
    HostName 10.0.1.50
    User deploy
    IdentityFile ~/.ssh/id_ed25519
    IdentitiesOnly yes

Problem 5: Remote Server Shell Not Compatible

The remote server uses a non-standard shell that VS Code cannot interact with:

bash
Remote server shell: /bin/fish

VS Code requires a POSIX-compatible shell. Fix by setting the remote shell:

bash
Host remote-server
    HostName 10.0.1.50
    User deploy
    SetEnv VSCODE_SHELL=/bin/bash

Or configure on the remote server:

bash
# Change default shell
chsh -s /bin/bash

Problem 6: Connection Timeout

The SSH connection times out during VS Code Server setup:

json
{
    "remote.SSH.connectTimeout": 30,
    "remote.SSH.serverInstallTimeout": 60
}

Increase these timeouts for slow connections or overloaded servers.

Debugging Remote SSH

Enable verbose logging:

json
{
    "remote.SSH.showLoginTerminal": true,
    "remote.SSH.loglevel": "debug"
}

Check the Remote SSH output:

bash
View > Output > Select "Remote - SSH" from dropdown

This shows the complete SSH connection process, including key exchange, authentication, and VS Code Server installation steps.

Testing SSH Connection Independently

Before debugging VS Code, verify SSH works from the command line:

bash
ssh -v remote-server

If this fails, the issue is with SSH configuration, not VS Code. Fix SSH first, then retry the VS Code connection.