{"record":{"id":"442e41f84e306316","repo":"lima-vm/lima","slug":"could-not-create-q-directory-w-442e41","errorCode":null,"errorMessage":"could not create %#q directory: %w","messagePattern":"could not create %#q directory: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/sshutil/sshutil.go","lineNumber":305,"sourceCode":"\n// DefaultPubKeys returns the public key from $LIMA_HOME/_config/user.pub.\n// The key will be created if it does not yet exist.\n//\n// When loadDotSSH is true, ~/.ssh/*.pub will be appended to make the VM accessible without specifying\n// an identity explicitly.\nfunc DefaultPubKeys(ctx context.Context, loadDotSSH bool) ([]PubKey, error) {\n\t// Read $LIMA_HOME/_config/user.pub\n\tconfigDir, err := dirnames.LimaConfigDir()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\t_, err = os.Stat(filepath.Join(configDir, filenames.UserPrivateKey))\n\tif err != nil {\n\t\tif !errors.Is(err, os.ErrNotExist) {\n\t\t\treturn nil, err\n\t\t}\n\t\tif err := os.MkdirAll(configDir, 0o700); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"could not create %#q directory: %w\", configDir, err)\n\t\t}\n\t\tif err := lockutil.WithDirLock(configDir, func() error {\n\t\t\t// no passphrase, no user@host comment\n\t\t\tprivPath := filepath.Join(configDir, filenames.UserPrivateKey)\n\t\t\tkeygenExe := \"ssh-keygen\"\n\t\t\tif runtime.GOOS == \"windows\" {\n\t\t\t\tsshExe, sshErr := NewSSHExe()\n\t\t\t\tif sshErr != nil {\n\t\t\t\t\treturn sshErr\n\t\t\t\t}\n\t\t\t\tkeygenExe = companionForSSH(sshExe, \"ssh-keygen\")\n\t\t\t\tprivPath, err = PathForSSH(ctx, sshExe, privPath)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t}\n\t\t\tkeygenCmd := exec.CommandContext(ctx, keygenExe, \"-t\", \"ed25519\", \"-q\", \"-N\", \"\",\n\t\t\t\t\"-C\", \"lima\", \"-f\", privPath)","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/sshutil/sshutil.go#L287-L323","documentation":"DefaultPubKeys ensures $LIMA_HOME/_config exists before generating a default key pair; if os.MkdirAll of that directory fails the error is wrapped with the directory path. This usually indicates a filesystem-level problem, not a Lima logic error.","triggerScenarios":"Calling DefaultPubKeys (directly or via templateArgs) when _config does not exist yet and MkdirAll fails: read-only $LIMA_HOME, permission denied on the parent, disk full, or the path exists as a non-directory (a file named _config).","commonSituations":"LIMA_HOME pointing at a read-only or non-writable location; a stale file where the _config directory should be; running under a user without write access to the home dir; NFS/Windows mount quirks.","solutions":["Verify $LIMA_HOME (default ~/.lima) is writable by the current user; create it manually with mkdir -p ~/.lima/_config and chmod 700.","If a regular file named _config exists, remove or rename it.","Check the wrapped OS error in the message for the concrete cause (EACCES, ENOSPC, ENOTDIR)."],"exampleFix":"// before\nexport LIMA_HOME=/mnt/readonly/lima\nlimactl create\n// after\nexport LIMA_HOME=$HOME/.lima\nmkdir -p \"$LIMA_HOME/_config\" && chmod 700 \"$LIMA_HOME/_config\"\nlimactl create","handlingStrategy":"validation","validationCode":"configDir := filepath.Join(limaHome, \"_config\")\nif info, err := os.Stat(configDir); err == nil && !info.IsDir() {\n    return fmt.Errorf(\"%s exists but is not a directory\", configDir)\n}\nif err := os.MkdirAll(configDir, 0o700); err != nil { return err }","typeGuard":"func writableDir(p string) bool { return os.MkdirAll(p, 0o700) == nil }","tryCatchPattern":"keys, err := sshutil.DefaultPubKeys(ctx)\nif err != nil {\n    if strings.Contains(err.Error(), \"could not create\") {\n        // check LIMA_HOME writability and report to user\n    }\n    return err\n}","preventionTips":["Verify LIMA_HOME points to a writable, local directory","Ensure nothing named _config exists as a regular file","Check disk space before instance creation"],"tags":["filesystem","permissions","ssh-keys"],"backgroundTag":"directory-create-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}