zed-industries/zed · error

ssh process exited before connection established

Error message

ssh process exited before connection established

What it means

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.

Solutions

  1. Run the equivalent command manually to see why ssh exits: `ssh -vvv <user>@<host>` in a terminal
  2. Fix user/port/credentials in Zed's remote connection options
  3. Install or repair the OpenSSH client (Windows Settings > Apps > Optional Features > OpenSSH Client) and confirm `where ssh` resolves it
  4. Pre-accept the host key: `ssh-keyscan <host> >> known_hosts`, or pass StrictHostKeyChecking=accept-new via additional ssh args

Example fix

# before: OpenSSH client missing on Windows, ssh exits instantly
where ssh   # not found

# after (PowerShell, admin)
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
# reconnect from Zed
Defensive patterns

Strategy: try-catch

Validate before calling

// Preflight from a terminal: a zero exit means ssh gets far enough to establish
// ssh -o BatchMode=yes -o ConnectTimeout=5 -T <user>@<host> true; echo $?

Try / catch

match master.wait_connected().await {
    Err(e) if e.to_string().contains("exited before connection established") => {
        // run `ssh -vvv user@host` manually and surface the real cause (auth/host/network)
        Err(e)
    }
    other => other,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/eaccf3066ab95bc2. Report an issue: GitHub.

Appendix: source

Thrown at crates/remote/src/transport/ssh.rs:279

        Ok(MasterProcess { process })
    }

    pub async fn wait_connected(&mut self) -> Result<()> {
        use smol::io::AsyncBufReadExt;

        let Some(stdout) = self.process.stdout.take() else {
            anyhow::bail!("ssh process stdout capture failed");
        };

        let mut reader = smol::io::BufReader::new(stdout);

        let mut line = String::new();

        loop {
            let n = reader.read_line(&mut line).await?;
            if n == 0 {
                anyhow::bail!("ssh process exited before connection established");
            }

            if line.contains(Self::CONNECTION_ESTABLISHED_MAGIC) {
                return Ok(());
            }
        }
    }
}

impl AsRef<Child> for MasterProcess {
    fn as_ref(&self) -> &Child {
        &self.process
    }
}

impl AsMut<Child> for MasterProcess {
    fn as_mut(&mut self) -> &mut Child {
        &mut self.process

View on GitHub (pinned to f4178619ac)