{"record":{"id":"2826ee00d9552db3","repo":"lima-vm/lima","slug":"failed-to-create-ssh-directory-for-user-q-w","errorCode":null,"errorMessage":"failed to create .ssh directory for user %#q: %w","messagePattern":"failed to create \\.ssh directory for user %#q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/guestagent/fakecloudinit/fakecloudinit_darwin.go","lineNumber":298,"sourceCode":"\tif err = populateHomeDir(ctx, uid, homedir); err != nil {\n\t\treturn fmt.Errorf(\"failed to populate home directory for user %#q: %w\", u.Name, err)\n\t}\n\n\tcmd = exec.CommandContext(ctx, \"chmod\", \"700\", homedir)\n\tlogrus.Infof(\"Executing command: %v\", cmd.Args)\n\tif output, err := cmd.CombinedOutput(); err != nil {\n\t\treturn fmt.Errorf(\"failed to execute command %v: %w (output=%#q)\", cmd.Args, err, output)\n\t}\n\n\tpwPath := filepath.Join(homedir, \"password\")\n\tif err = os.WriteFile(pwPath, []byte(pw+\"\\n\"), 0o400); err != nil {\n\t\treturn fmt.Errorf(\"failed to write password file for user %#q: %w\", u.Name, err)\n\t}\n\tlogrus.Infof(\"Created user %#q. The password is stored in %#q\", u.Name, pwPath)\n\n\tdotSSHPath := filepath.Join(homedir, \".ssh\")\n\tif err = os.MkdirAll(dotSSHPath, 0o700); err != nil {\n\t\treturn fmt.Errorf(\"failed to create .ssh directory for user %#q: %w\", u.Name, err)\n\t}\n\tauthKeysPath := filepath.Join(dotSSHPath, \"authorized_keys\")\n\tauthKeysContent := strings.Join(u.SSHAuthorizedKeys, \"\\n\")\n\tif err = os.WriteFile(authKeysPath, []byte(authKeysContent), 0o600); err != nil {\n\t\treturn fmt.Errorf(\"failed to write authorized_keys file for user %#q: %w\", u.Name, err)\n\t}\n\tfor _, f := range []string{pwPath, dotSSHPath, authKeysPath} {\n\t\tif err = os.Chown(f, uid, -1); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to chown %#q for user %#q: %w\", f, u.Name, err)\n\t\t}\n\t}\n\tif u.Sudo != \"\" {\n\t\tif err := writeSudoers(u.Name, u.Sudo); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to write sudoers file for user %#q: %w\", u.Name, err)\n\t\t}\n\t}\n\treturn nil\n}","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/guestagent/fakecloudinit/fakecloudinit_darwin.go#L280-L316","documentation":"The agent could not create the `<homedir>/.ssh` directory (mode 0700) for the freshly created user. This directory is required to install `authorized_keys`. The error wraps the raw os.MkdirAll failure and aborts provisioning of this user.","triggerScenarios":"os.MkdirAll(homedir/.ssh, 0o700) fails in createUser during processUserData on a darwin guest. Causes: home path is a file instead of a directory, parent not writable, ENOSPC, or read-only filesystem.","commonSituations":"A stale file named `.ssh` exists at the home path from a previous provisioning attempt; the custom `home` from user-data points into a read-only or restricted location; disk image full.","solutions":["Check for a conflicting file at `<homedir>/.ssh` and remove it","Verify disk space and writability of the home directory as root","Read the wrapped errno in the error message to pinpoint the cause","Delete and recreate the instance if prior partial provisioning left bad state"],"exampleFix":"// inside the VM, before reprovisioning\nsudo rm -f /Users/alice/.ssh   # if it exists as a regular file","handlingStrategy":"validation","validationCode":"sshDir := filepath.Join(home, \".ssh\")\nif st, err := os.Lstat(sshDir); err == nil && !st.IsDir() {\n    return fmt.Errorf(\"%s exists and is not a directory; remove it first\", sshDir)\n}","typeGuard":null,"tryCatchPattern":"if err := processUserData(ctx, data); err != nil {\n    var pe *os.PathError\n    if errors.As(err, &pe) && strings.Contains(err.Error(), \".ssh directory\") {\n        log.Printf(\"mkdir %s failed: %v\", pe.Path, pe.Err)\n    }\n}","preventionTips":["Delete stale `.ssh` files from earlier failed provisions","Verify writability of the home directory as root before provisioning","Watch guest disk usage (df -h) before reprovisioning"],"tags":["filesystem","ssh","macos","guestagent"],"backgroundTag":"mkdir-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}