{"record":{"id":"eaccf3066ab95bc2","repo":"zed-industries/zed","slug":"ssh-process-exited-before-connection-established","errorCode":null,"errorMessage":"ssh process exited before connection established","messagePattern":"ssh process exited before connection established","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/remote/src/transport/ssh.rs","lineNumber":279,"sourceCode":"\n        Ok(MasterProcess { process })\n    }\n\n    pub async fn wait_connected(&mut self) -> Result<()> {\n        use smol::io::AsyncBufReadExt;\n\n        let Some(stdout) = self.process.stdout.take() else {\n            anyhow::bail!(\"ssh process stdout capture failed\");\n        };\n\n        let mut reader = smol::io::BufReader::new(stdout);\n\n        let mut line = String::new();\n\n        loop {\n            let n = reader.read_line(&mut line).await?;\n            if n == 0 {\n                anyhow::bail!(\"ssh process exited before connection established\");\n            }\n\n            if line.contains(Self::CONNECTION_ESTABLISHED_MAGIC) {\n                return Ok(());\n            }\n        }\n    }\n}\n\nimpl AsRef<Child> for MasterProcess {\n    fn as_ref(&self) -> &Child {\n        &self.process\n    }\n}\n\nimpl AsMut<Child> for MasterProcess {\n    fn as_mut(&mut self) -> &mut Child {\n        &mut self.process","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/remote/src/transport/ssh.rs#L261-L297","documentation":"On the Windows connect path, wait_connected reads ssh's stdout line by line until the ZED_SSH_CONNECTION_ESTABLISHED magic appears; read_line returning 0 bytes is EOF, meaning the ssh master process exited before it ever printed the marker, so connection establishment cannot complete.","triggerScenarios":"The ssh.exe master process terminates during the handshake: authentication failure, unreachable host, bad port/user, malformed ssh arguments, or ssh.exe missing from PATH so the spawn target fails immediately.","commonSituations":"Windows machines without the OpenSSH client optional feature installed; wrong username/port in the remote connection options; host key prompts hitting a non-interactive channel; mistyped or stale connection settings.","solutions":["Run the equivalent command manually to see why ssh exits: `ssh -vvv <user>@<host>` in a terminal","Fix user/port/credentials in Zed's remote connection options","Install or repair the OpenSSH client (Windows Settings > Apps > Optional Features > OpenSSH Client) and confirm `where ssh` resolves it","Pre-accept the host key: `ssh-keyscan <host> >> known_hosts`, or pass StrictHostKeyChecking=accept-new via additional ssh args"],"exampleFix":"# before: OpenSSH client missing on Windows, ssh exits instantly\nwhere ssh   # not found\n\n# after (PowerShell, admin)\nAdd-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0\n# reconnect from Zed","handlingStrategy":"try-catch","validationCode":"// Preflight from a terminal: a zero exit means ssh gets far enough to establish\n// ssh -o BatchMode=yes -o ConnectTimeout=5 -T <user>@<host> true; echo $?","typeGuard":null,"tryCatchPattern":"match master.wait_connected().await {\n    Err(e) if e.to_string().contains(\"exited before connection established\") => {\n        // run `ssh -vvv user@host` manually and surface the real cause (auth/host/network)\n        Err(e)\n    }\n    other => other,\n}","preventionTips":["Pre-accept host keys with ssh-keyscan to avoid prompt-then-exit","Verify the OpenSSH client is installed and first on PATH on Windows","Validate user/port and key loading before automating connections"],"tags":["ssh","windows","connection","auth"],"backgroundTag":"ssh-connection-failed","analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}