{"record":{"id":"b4d42d29cc4811e3","repo":"lima-vm/lima","slug":"failed-to-read-ssh-public-key-q-w","errorCode":null,"errorMessage":"failed to read ssh public key %#q: %w","messagePattern":"failed to read ssh public key %#q: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/sshutil/sshutil.go","lineNumber":283,"sourceCode":"\t\treturn \"\"\n\t}\n\treturn sftpServer\n}\n\ntype PubKey struct {\n\tFilename string\n\tContent  string\n}\n\nfunc readPublicKey(f string) (PubKey, error) {\n\tentry := PubKey{\n\t\tFilename: f,\n\t}\n\tcontent, err := os.ReadFile(f)\n\tif err == nil {\n\t\tentry.Content = strings.TrimSpace(string(content))\n\t} else {\n\t\terr = fmt.Errorf(\"failed to read ssh public key %#q: %w\", f, err)\n\t}\n\treturn entry, err\n}\n\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) {","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/sshutil/sshutil.go#L265-L301","documentation":"readPublicKey wraps os.ReadFile failures for an SSH public key file (such as $LIMA_HOME/_config/user.pub) with the file path and the underlying OS error. The entry is still returned with an empty Content so callers can see which file failed.","triggerScenarios":"DefaultPubKeys enumerates known public key files and calls readPublicKey; os.ReadFile fails with permission denied, an I/O error, or a race where the file disappears between existence check and read.","commonSituations":"_config/user.pub exists but is unreadable (wrong ownership/permissions, root-owned after sudo usage); file deleted concurrently; filesystem errors (full disk, broken symlink target).","solutions":["Check permissions on the key file: it should be readable by the current user (chmod 600, chown to your user).","Regenerate the key pair with limactl or ssh-keygen if user.pub is corrupted or root-owned.","Investigate the wrapped OS error (path printed in the message) for the concrete cause (ENOENT, EACCES, etc.)."],"exampleFix":"// before\nsudo limactl start   # created _config/user.pub owned by root\n// after\nsudo chown -R \"$USER\" ~/.lima/_config\nchmod 600 ~/.lima/_config/user","handlingStrategy":"try-catch","validationCode":"if _, err := os.Stat(pubKeyPath); err != nil { /* skip: key missing, let DefaultPubKeys create it */ }\nif info, err := os.Stat(pubKeyPath); err == nil && !info.Mode().IsRegular() { /* not a normal file */ }","typeGuard":"func readable(f string) bool { h, err := os.Open(f); if err != nil { return false }; h.Close(); return true }","tryCatchPattern":"keys, err := sshutil.DefaultPubKeys(ctx)\nif err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) { /* inspect pe.Path / pe.Err */ }\n    return err\n}","preventionTips":["Keep $LIMA_HOME owned by the running user","Never run limactl under sudo (creates root-owned keys)","Back up user.pub before manual edits"],"tags":["ssh","file-io","permissions"],"backgroundTag":"key-file-read-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}