VS Code Remote SSH drops connection every few minutes on macOS Sonoma
Problem
VS Code Remote SSH connections drop every 3–10 minutes with 'Connection to server closed' on macOS Sonoma. The issue started after upgrading macOS. macOS Sonoma introduced more aggressive network connection management that closes idle TCP connections. SSH connections without keepalive packets are silently terminated by the OS networking stack.
Error Output
Connection to server closed [Error] Could not establish connection to "myserver": The VS Code Server failed to start.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Add SSH keepalive settings to ~/.ssh/config
macOS Sonoma closes idle TCP connections aggressively. SSH connections without keepalive packets are silently terminated by the OS before VS Code detects the disconnect.
Trust Score
8 verifications
- 1
Add keepalive to ~/.ssh/config
Edit or create ~/.ssh/config:
textHost * ServerAliveInterval 60 ServerAliveCountMax 3 TCPKeepAlive yes - 2
Enable TCP keepalive at the OS level
In Terminal:
bashsudo pmset -a tcpkeepalive 1 - 3
Close and reopen the VS Code Remote SSH connection
Press Cmd+Shift+P → Remote-SSH: Kill VS Code Server on Host, then reconnect.
Validation
Remote SSH session stays connected for 30+ minutes of idle time without dropping.
Verification Summary
Sign in to verify this fix
Environment
- Product
- VS Code Remote SSH
- OS
- macOS Sonoma 14
- Environment
- development
Submitted by
Alex Chen
2450 rep