Skip to content

fix: Windows ssh command quoting #1863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions pkg/sshutil/sshutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ func CommonOpts(useDotSSH bool) ([]string, error) {
var opts []string
if runtime.GOOS == "windows" {
privateKeyPath = ioutilx.CanonicalWindowsPath(privateKeyPath)
opts = []string{fmt.Sprintf(`IdentityFile='%s'`, privateKeyPath)}
} else {
opts = []string{fmt.Sprintf(`IdentityFile="%s"`, privateKeyPath)}
}
opts = []string{fmt.Sprintf(`IdentityFile="%s"`, privateKeyPath)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we can use the "windows" form for non-windows too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that at first, but some of the e2e tests were failing :(. Example: https://github.com/lima-vm/lima/actions/runs/6355908876


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

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