Skip to content

Commit e7f8ffb

Browse files
authored
Merge pull request #1863 from pendo324/windows-ssh-quoting
fix: Windows ssh command quoting
2 parents de100c6 + e89048c commit e7f8ffb

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pkg/sshutil/sshutil.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@ func CommonOpts(useDotSSH bool) ([]string, error) {
138138
var opts []string
139139
if runtime.GOOS == "windows" {
140140
privateKeyPath = ioutilx.CanonicalWindowsPath(privateKeyPath)
141+
opts = []string{fmt.Sprintf(`IdentityFile='%s'`, privateKeyPath)}
142+
} else {
143+
opts = []string{fmt.Sprintf(`IdentityFile="%s"`, privateKeyPath)}
141144
}
142-
opts = []string{fmt.Sprintf(`IdentityFile="%s"`, privateKeyPath)}
143145

144146
// Append all private keys corresponding to ~/.ssh/*.pub to keep old instances working
145147
// that had been created before lima started using an internal identity.
@@ -170,7 +172,11 @@ func CommonOpts(useDotSSH bool) ([]string, error) {
170172
// Fail on permission-related and other path errors
171173
return nil, err
172174
}
173-
opts = append(opts, "IdentityFile=\""+privateKeyPath+"\"")
175+
if runtime.GOOS == "windows" {
176+
opts = append(opts, fmt.Sprintf(`IdentityFile='%s'`, privateKeyPath))
177+
} else {
178+
opts = append(opts, fmt.Sprintf(`IdentityFile="%s"`, privateKeyPath))
179+
}
174180
}
175181
}
176182

@@ -229,10 +235,11 @@ func SSHOpts(instDir string, useDotSSH, forwardAgent bool, forwardX11 bool, forw
229235
if err != nil {
230236
return nil, err
231237
}
238+
controlPath := fmt.Sprintf(`ControlPath="%s"`, controlSock)
232239
if runtime.GOOS == "windows" {
233240
controlSock = ioutilx.CanonicalWindowsPath(controlSock)
241+
controlPath = fmt.Sprintf(`ControlPath='%s'`, controlSock)
234242
}
235-
controlPath := fmt.Sprintf(`ControlPath="%s"`, controlSock)
236243
opts = append(opts,
237244
fmt.Sprintf("User=%s", u.Username), // guest and host have the same username, but we should specify the username explicitly (#85)
238245
"ControlMaster=auto",

0 commit comments

Comments
 (0)