{"record":{"id":"c5a0dca7e5f94b83","repo":"kubernetes/kops","slug":"error-reading-ssh-public-key-files-q-v","errorCode":null,"errorMessage":"error reading SSH public key files %q: %v","messagePattern":"error reading SSH public key files %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/create_cluster.go","lineNumber":857,"sourceCode":"\t\t\tsshPublicKeyPaths := []string{\n\t\t\t\t\"~/.ssh/id_ed25519.pub\",\n\t\t\t\t\"~/.ssh/id_rsa.pub\",\n\t\t\t}\n\t\t\tvar merr error\n\t\t\tfor _, sshPublicKeyPath := range sshPublicKeyPaths {\n\t\t\t\tc.SSHPublicKeys, err = loadSSHPublicKeys(sshPublicKeyPath)\n\t\t\t\tif err == nil {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\t// Don't wrap file-not-found\n\t\t\t\tif os.IsNotExist(err) {\n\t\t\t\t\tklog.V(2).Infof(\"ssh key not found at %s\", sshPublicKeyPath)\n\t\t\t\t} else {\n\t\t\t\t\tmerr = multierr.Append(merr, err)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif merr != nil && len(c.SSHPublicKeys) == 0 {\n\t\t\t\treturn fmt.Errorf(\"error reading SSH public key files %q: %v\", sshPublicKeyPaths, merr)\n\t\t\t}\n\t\t}\n\t}\n\n\tif len(c.SSHPublicKeys) != 0 {\n\t\tsshCredentialStore, err := clientset.SSHCredentialStore(cluster)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tfor _, data := range c.SSHPublicKeys {\n\t\t\terr = sshCredentialStore.AddSSHPublicKey(ctx, data)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error adding SSH public key: %v\", err)\n\t\t\t}\n\t\t}\n\t}\n","sourceCodeStart":839,"sourceCodeEnd":875,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/create_cluster.go#L839-L875","documentation":"When no explicit SSH public keys were given, kops tries to autoload keys from standard locations (e.g. ~/.ssh/id_rsa.pub, ~/.ssh/id_ed25519.pub) and accumulates read errors in a multierr. If every autoload attempt failed and no keys were provided at all, this error aborts the command listing all paths attempted. Cluster creation stops because no SSH credential could be registered.","triggerScenarios":"`kops create cluster` without --ssh-public-key on a machine where the default ~/.ssh public key files are absent or unreadable, and the cloud provider is not gce/aws (which skip autoloading).","commonSituations":"Fresh VM/container with no generated SSH keys; keys generated under nonstandard filenames; HOME unset in CI so ~/.ssh resolves incorrectly; restrictive file permissions.","solutions":["Generate a key: ssh-keygen -t ed25519 (writes ~/.ssh/id_ed25519.pub).","Pass the key explicitly: --ssh-public-key ~/.ssh/id_rsa.pub.","Fix file permissions (chmod 644 ~/.ssh/*.pub) or HOME resolution in the environment.","Supply the key explicitly on gce/aws too, to avoid relying on autoload behavior."],"exampleFix":"// before\nkops create cluster --name c.k8s.local --zones us-east-1a   # no key in ~/.ssh\n// after\nssh-keygen -t ed25519 -N '' -f ~/.ssh/id_ed25519\nkops create cluster --name c.k8s.local --zones us-east-1a","handlingStrategy":"validation","validationCode":"func ensureSSHPublicKey(explicit string) (string, error) {\n\tif explicit != \"\" {\n\t\tif _, err := os.Stat(explicit); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"ssh key %s missing: %w\", explicit, err)\n\t\t}\n\t\treturn explicit, nil\n\t}\n\tfor _, p := range []string{\"~/.ssh/id_ed25519.pub\", \"~/.ssh/id_rsa.pub\"} {\n\t\tif expanded, err := homedir.Expand(p); err == nil {\n\t\t\tif _, err := os.Stat(expanded); err == nil {\n\t\t\t\treturn expanded, nil\n\t\t\t}\n\t\t}\n\t}\n\treturn \"\", fmt.Errorf(\"no SSH public key found; pass --ssh-public-key\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass --ssh-public-key explicitly in scripts and CI.","Run ssh-keygen once when provisioning dev machines/containers.","Ensure HOME is set correctly in CI environments.","Keep default key files readable (chmod 644 *.pub)."],"tags":["cli","ssh","file-io"],"backgroundTag":"missing-ssh-public-key","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}