@@ -98,8 +98,15 @@ func DefaultPubKeys(loadDotSSH bool) ([]PubKey, error) {
9898 }
9999 if err := lockutil .WithDirLock (configDir , func () error {
100100 // 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+ }
101108 keygenCmd := exec .Command ("ssh-keygen" , "-t" , "ed25519" , "-q" , "-N" , "" ,
102- "-C" , "lima" , "-f" , filepath . Join ( configDir , filenames . UserPrivateKey ) )
109+ "-C" , "lima" , "-f" , privPath )
103110 logrus .Debugf ("executing %v" , keygenCmd .Args )
104111 if out , err := keygenCmd .CombinedOutput (); err != nil {
105112 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) {
171178 return nil , err
172179 }
173180 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
179184 }
185+ opts = []string {idf }
180186
181187 // Append all private keys corresponding to ~/.ssh/*.pub to keep old instances working
182188 // that had been created before lima started using an internal identity.
@@ -207,11 +213,11 @@ func CommonOpts(sshPath string, useDotSSH bool) ([]string, error) {
207213 // Fail on permission-related and other path errors
208214 return nil , err
209215 }
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
214219 }
220+ opts = append (opts , idf )
215221 }
216222 }
217223
@@ -256,6 +262,17 @@ func CommonOpts(sshPath string, useDotSSH bool) ([]string, error) {
256262 return opts , nil
257263}
258264
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+
259276// SSHOpts adds the following options to CommonOptions: User, ControlMaster, ControlPath, ControlPersist.
260277func SSHOpts (sshPath , instDir , username string , useDotSSH , forwardAgent , forwardX11 , forwardX11Trusted bool ) ([]string , error ) {
261278 controlSock := filepath .Join (instDir , filenames .SSHSock )
@@ -268,7 +285,10 @@ func SSHOpts(sshPath, instDir, username string, useDotSSH, forwardAgent, forward
268285 }
269286 controlPath := fmt .Sprintf (`ControlPath="%s"` , controlSock )
270287 if runtime .GOOS == "windows" {
271- controlSock = ioutilx .CanonicalWindowsPath (controlSock )
288+ controlSock , err = ioutilx .WindowsSubsystemPath (controlSock )
289+ if err != nil {
290+ return nil , err
291+ }
272292 controlPath = fmt .Sprintf (`ControlPath='%s'` , controlSock )
273293 }
274294 opts = append (opts ,
0 commit comments