I'm working with VSCode (Cursor actually), I'm connecting with ssh remotly. It…
- User
I'm working with VSCode (Cursor actually), I'm connecting with ssh remotly. It disconnect a lot, after few minitues or less, and then I need to provide again the otp and password and that's frustrating. Any chance that there is a default timeout that is causeing it? something that can be configured?
Assistant
This is a very common frustration with VSCode/Cursor when working with SSH. The "timeout" isn't usually in the editor itself, but in the network connection (firewalls, routers, or the server itself) silently dropping "idle" TCP connections.Because SSH doesn't send data when you aren't typing, the network thinks the connection is dead and cuts it. When you try to type again, the editor realizes the pipe is broken and forces you to reconnect.Here are three steps to fix this, ranked from "most likely to help" to "quality of life improvement."1. The "KeepAlive" Fix (Best Solution)You can force your local SSH client to send a "heartbeat" signal to the server every few seconds. This tricks the network into thinking the connection is busy, preventing the timeout.Modify your SSH Config file locally:Open Cursor.Press Cmd+Shift+P (Mac) or Ctrl+Shift+P (Windows/Linux).Type "Remote-SSH: Open SSH Configuration File" and select it.Choose your config file (usually ~/.ssh/config or C:\Users\You.ssh\config).Add the ServerAliveInterval and ServerAliveCountMax lines to your host entry:Code snippetHost your-remote-server-alias HostName 198.51.97.125 User username # Send a heartbeat every 60 seconds ServerAliveInterval 60 # Disconnect only if server fails to respond 3 times in a row ServerAliveCountMax 3 Note: If you want this to apply to all your connections, you can put these lines under a Host * entry at the top of the file.2. The Cursor-Specific CheckSince you are using Cursor, you might be using the wrong SSH extension. The standard Microsoft "Remote - SSH" extension sometimes conflicts with Cursor because it looks for specific VSCode validation hashes.Check your Extensions: Go to the extensions tab in Cursor.Look for: "Remote - SSH".Verify: Ensure you are using the Cursor-native version (often built-in or managed by Cursor) rather than the standard Microsoft one.Fix: If you suspect a conflict, some users find stability by uninstalling the Microsoft "Remote - SSH" extension and letting Cursor reinstall its own compatible version/handler.3. The "Stop Asking for OTP" Fix (ControlMaster)This won't stop the disconnects, but it will make them much less painful. SSH "Multiplexing" allows you to open one master connection and have all subsequent windows/terminals piggyback off it without asking for a password or OTP again.Add this to your ~/.ssh/config file (same place as step 1):Code snippetHost * ControlMaster auto ControlPath ~/.ssh/sockets/%r@%h-%p ControlPersist 600 ControlPersist 600: Means "keep the master connection open for 10 minutes (600 seconds) even after I close the window."Result: If you disconnect, you can just hit "Reload Window" and it will reconnect instantly without asking for your password/OTP, as long as the master connection is still alive.Note for Windows Users: ControlMaster works best in WSL or Git Bash; it may not work with the default Windows OpenSSH client.4. Adjust Editor Timeout SettingsThere is one specific setting in Cursor/VSCode that controls how long it waits before giving up on a connection.Open Settings (Cmd+, or Ctrl+,).Search for remote.SSH.connectTimeout.Increase this value (default is usually 15 seconds). Try setting it to 60.Summary of the "Why"You asked if a default timeout is causing this. Yes, but it's likely an idle timeout on a firewall or load balancer between you and the server (often defaulting to 5 minutes). By using Step 1, you defeat this timeout by ensuring the connection is never truly "idle."Would you like me to help you verify if the ControlMaster socket path is valid for your specific operating system?VSCode Remote SSH: Disconnected Attempting to reconnect This video is relevant because it visually demonstrates the exact "ServerAliveInterval" configuration in the SSH config file discussed in Step 1, which is the primary fix for your issue.VSCode Remote SSH: Disconnected Attempting to reconnect - YouTubeSusan B. · 6.7K views