@@ -15,6 +15,7 @@ import (
1515 "os"
1616 "os/exec"
1717 "path/filepath"
18+ "runtime"
1819 "strconv"
1920 "strings"
2021 "sync"
@@ -265,6 +266,20 @@ func writeSSHConfigFile(sshPath, instName, instDir, instSSHAddress string, sshLo
265266# This file is created by Lima, but not used by Lima itself currently.
266267# Modifications to this file will be lost on restarting the Lima instance.
267268` )
269+ if runtime .GOOS == "windows" {
270+ // Remove ControlMaster, ControlPath, and ControlPersist options,
271+ // because Cygwin-based SSH clients do not support multiplexing when executing commands.
272+ // References:
273+ // https://inbox.sourceware.org/cygwin/c98988a5-7e65-4282-b2a1-bb8e350d5fab@acm.org/T/
274+ // https://stackoverflow.com/questions/20959792/is-ssh-controlmaster-with-cygwin-on-windows-actually-possible
275+ // By removing these options:
276+ // - Avoids execution failures when the control master is not yet available.
277+ // - Prevents error messages such as:
278+ // > mux_client_request_session: read from master failed: Connection reset by peer
279+ // > ControlSocket ....sock already exists, disabling multiplexing
280+ // Only remove these options when writing the SSH config file and executing `limactl shell`, since multiplexing seems to work with port forwarding.
281+ sshOpts = sshutil .SSHOptsRemovingControlPath (sshOpts )
282+ }
268283 if err := sshutil .Format (b , sshPath , instName , sshutil .FormatConfig ,
269284 append (sshOpts ,
270285 fmt .Sprintf ("Hostname=%s" , instSSHAddress ),
0 commit comments