FG
🛠️ Developer ToolsMicrosoftmacOS Sonoma 14development

VS Code Remote SSH drops connection every few minutes on macOS Sonoma

Fresh6 months ago
Mar 14, 20260 views
Confidence Score73%
73%

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

Canonical Fix
Moderate Confidence Fix
69% confidence77% success rate8 verificationsLast verified Mar 14, 2026

Add SSH keepalive settings to ~/.ssh/config

Low Risk

macOS Sonoma closes idle TCP connections aggressively. SSH connections without keepalive packets are silently terminated by the OS before VS Code detects the disconnect.

69

Trust Score

8 verifications

77% success
  1. 1

    Add keepalive to ~/.ssh/config

    Edit or create ~/.ssh/config:

    text
    Host *
      ServerAliveInterval 60
      ServerAliveCountMax 3
      TCPKeepAlive yes
  2. 2

    Enable TCP keepalive at the OS level

    In Terminal:

    bash
    sudo pmset -a tcpkeepalive 1
  3. 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

Worked: 8
Partial: 2
Failed: 3
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Product
VS Code Remote SSH
OS
macOS Sonoma 14
Environment
development

Submitted by

AC

Alex Chen

2450 rep

Tags

vscoderemote-sshmacos-sonomadisconnecttcp-keepalive