# 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:
Could not establish connection to "remote-server"The Output panel shows:
SSH ERROR: kex_exchange_identification: Connection closed by remote hostOr:
SSH ERROR: Unable to negotiate with 10.0.1.50 port 22: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1Or:
SSH ERROR: no matching host key type found. Their offer: ssh-rsa,ssh-dssThese 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):
Host remote-server
HostName 10.0.1.50
User deploy
KexAlgorithms +diffie-hellman-group1-sha1The + 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:
Host legacy-server
HostName 192.168.1.100
User admin
HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsaProblem 3: VS Code Server Installation Failed
Even if SSH connects successfully, VS Code may fail to install its server component on the remote machine:
Installing VS Code Server on the remote...
Failed to install VS Code ServerCheck 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:
# 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=1Problem 4: SSH Key Not Accepted
The remote server rejects your SSH key:
Permission denied (publickey,password).Check which keys are being offered:
ssh -v remote-server 2>&1 | grep "Offering public key"If your key is not listed, add it to the SSH agent:
ssh-add ~/.ssh/id_ed25519Or specify it in SSH config:
Host remote-server
HostName 10.0.1.50
User deploy
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yesProblem 5: Remote Server Shell Not Compatible
The remote server uses a non-standard shell that VS Code cannot interact with:
Remote server shell: /bin/fishVS Code requires a POSIX-compatible shell. Fix by setting the remote shell:
Host remote-server
HostName 10.0.1.50
User deploy
SetEnv VSCODE_SHELL=/bin/bashOr configure on the remote server:
# Change default shell
chsh -s /bin/bashProblem 6: Connection Timeout
The SSH connection times out during VS Code Server setup:
{
"remote.SSH.connectTimeout": 30,
"remote.SSH.serverInstallTimeout": 60
}Increase these timeouts for slow connections or overloaded servers.
Debugging Remote SSH
Enable verbose logging:
{
"remote.SSH.showLoginTerminal": true,
"remote.SSH.loglevel": "debug"
}Check the Remote SSH output:
View > Output > Select "Remote - SSH" from dropdownThis 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:
ssh -v remote-serverIf this fails, the issue is with SSH configuration, not VS Code. Fix SSH first, then retry the VS Code connection.