@@ -98,8 +98,15 @@ func DefaultPubKeys(loadDotSSH bool) ([]PubKey, error) {
98
98
}
99
99
if err := lockutil .WithDirLock (configDir , func () error {
100
100
// no passphrase, no user@host comment
101
+ privPath := filepath .Join (configDir , filenames .UserPrivateKey )
102
+ if runtime .GOOS == "windows" {
103
+ privPath , err = ioutilx .WindowsSubsystemPath (privPath )
104
+ if err != nil {
105
+ return err
106
+ }
107
+ }
101
108
keygenCmd := exec .Command ("ssh-keygen" , "-t" , "ed25519" , "-q" , "-N" , "" ,
102
- "-C" , "lima" , "-f" , filepath . Join ( configDir , filenames . UserPrivateKey ) )
109
+ "-C" , "lima" , "-f" , privPath )
103
110
logrus .Debugf ("executing %v" , keygenCmd .Args )
104
111
if out , err := keygenCmd .CombinedOutput (); err != nil {
105
112
return fmt .Errorf ("failed to run %v: %q: %w" , keygenCmd .Args , string (out ), err )
@@ -171,12 +178,11 @@ func CommonOpts(sshPath string, useDotSSH bool) ([]string, error) {
171
178
return nil , err
172
179
}
173
180
var opts []string
174
- if runtime .GOOS == "windows" {
175
- privateKeyPath = ioutilx .CanonicalWindowsPath (privateKeyPath )
176
- opts = []string {fmt .Sprintf (`IdentityFile='%s'` , privateKeyPath )}
177
- } else {
178
- opts = []string {fmt .Sprintf (`IdentityFile="%s"` , privateKeyPath )}
181
+ idf , err := identityFileEntry (privateKeyPath )
182
+ if err != nil {
183
+ return nil , err
179
184
}
185
+ opts = []string {idf }
180
186
181
187
// Append all private keys corresponding to ~/.ssh/*.pub to keep old instances working
182
188
// that had been created before lima started using an internal identity.
@@ -207,11 +213,11 @@ func CommonOpts(sshPath string, useDotSSH bool) ([]string, error) {
207
213
// Fail on permission-related and other path errors
208
214
return nil , err
209
215
}
210
- if runtime .GOOS == "windows" {
211
- opts = append (opts , fmt .Sprintf (`IdentityFile='%s'` , privateKeyPath ))
212
- } else {
213
- opts = append (opts , fmt .Sprintf (`IdentityFile="%s"` , privateKeyPath ))
216
+ idf , err = identityFileEntry (privateKeyPath )
217
+ if err != nil {
218
+ return nil , err
214
219
}
220
+ opts = append (opts , idf )
215
221
}
216
222
}
217
223
@@ -256,6 +262,17 @@ func CommonOpts(sshPath string, useDotSSH bool) ([]string, error) {
256
262
return opts , nil
257
263
}
258
264
265
+ func identityFileEntry (privateKeyPath string ) (string , error ) {
266
+ if runtime .GOOS == "windows" {
267
+ privateKeyPath , err := ioutilx .WindowsSubsystemPath (privateKeyPath )
268
+ if err != nil {
269
+ return "" , err
270
+ }
271
+ return fmt .Sprintf (`IdentityFile='%s'` , privateKeyPath ), nil
272
+ }
273
+ return fmt .Sprintf (`IdentityFile="%s"` , privateKeyPath ), nil
274
+ }
275
+
259
276
// SSHOpts adds the following options to CommonOptions: User, ControlMaster, ControlPath, ControlPersist.
260
277
func SSHOpts (sshPath , instDir , username string , useDotSSH , forwardAgent , forwardX11 , forwardX11Trusted bool ) ([]string , error ) {
261
278
controlSock := filepath .Join (instDir , filenames .SSHSock )
@@ -268,7 +285,10 @@ func SSHOpts(sshPath, instDir, username string, useDotSSH, forwardAgent, forward
268
285
}
269
286
controlPath := fmt .Sprintf (`ControlPath="%s"` , controlSock )
270
287
if runtime .GOOS == "windows" {
271
- controlSock = ioutilx .CanonicalWindowsPath (controlSock )
288
+ controlSock , err = ioutilx .WindowsSubsystemPath (controlSock )
289
+ if err != nil {
290
+ return nil , err
291
+ }
272
292
controlPath = fmt .Sprintf (`ControlPath='%s'` , controlSock )
273
293
}
274
294
opts = append (opts ,
0 commit comments