{"record":{"id":"70d2d1d9f1c09407","repo":"kubernetes/kops","slug":"error-reading-ssh-public-key-v-v","errorCode":null,"errorMessage":"error reading SSH public key %v: %v","messagePattern":"error reading SSH public key (.+?): (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/create_sshpublickey.go","lineNumber":94,"sourceCode":"func RunCreateSSHPublicKey(ctx context.Context, f *util.Factory, out io.Writer, options *CreateSSHPublicKeyOptions) error {\n\tcluster, err := GetCluster(ctx, f, options.ClusterName)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tclientset, err := f.KopsClient()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tsshCredentialStore, err := clientset.SSHCredentialStore(cluster)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tdata, err := os.ReadFile(options.PublicKeyPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error reading SSH public key %v: %v\", options.PublicKeyPath, err)\n\t}\n\n\terr = sshCredentialStore.AddSSHPublicKey(ctx, data)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error adding SSH public key: %v\", err)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":76,"sourceCodeEnd":104,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/create_sshpublickey.go#L76-L104","documentation":"Returned by `kops create secret sshpublickey` when `os.ReadFile` fails to read the SSH public key file at `options.PublicKeyPath`. The raw bytes of the public key are needed to store it in the cluster's SSH credential store; the wrapped OS error explains why the read failed.","triggerScenarios":"Running `kops create secret sshpublickey --name <cluster> -i <path>` where the `-i`/`--pubkey` path doesn't exist, is a directory, or is unreadable by the current user.","commonSituations":"Passing the private key path or a path that doesn't exist; using `~/.ssh/id_rsa.pub` from a machine without that key; relative path from a different working directory; permission errors on shared CI runners.","solutions":["Verify the path with `ls -l <path>` and correct typos; use an absolute path.","Ensure you pass the PUBLIC key file (e.g. id_rsa.pub / id_ed25519.pub), not the private key.","Fix file permissions so the running user can read the key."],"exampleFix":"// before\nkops create secret sshpublickey --name c.example.com -i ~/.ssh/id_rsa\n// after\nkops create secret sshpublickey --name c.example.com -i ~/.ssh/id_rsa.pub","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nif (!fs.existsSync(pubKeyPath) || !fs.statSync(pubKeyPath).isFile()) {\n  throw new Error(`SSH public key file not found: ${pubKeyPath}`);\n}","typeGuard":"function isReadableFile(p) {\n  try { return require('fs').statSync(p).isFile(); } catch { return false; }\n}","tryCatchPattern":"try {\n  runKops(['create','secret','sshpublickey', cluster, '-i', pubKeyPath]);\n} catch (e) {\n  if (/error reading SSH public key/.test(e.message)) {\n    console.error(`Cannot read ${pubKeyPath}; check path/permissions.`);\n  }\n  throw e;\n}","preventionTips":["Always pass the .pub file, never the private key","Use absolute paths in automation","Verify key presence before cluster setup scripts run"],"tags":["cli","ssh","filesystem","kops"],"backgroundTag":"file-not-found","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"}