{"record":{"id":"19532bc1ba93b210","repo":"kubernetes/kops","slug":"error-reading-ssh-key-file-q-v","errorCode":null,"errorMessage":"error reading SSH key file %q: %v","messagePattern":"error reading SSH key file %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/create_cluster.go","lineNumber":222,"sourceCode":"\t\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\t\tvar err error\n\n\t\t\tif cmd.Flag(\"associate-public-ip\").Changed {\n\t\t\t\toptions.AssociatePublicIP = &associatePublicIP\n\t\t\t}\n\n\t\t\tif cmd.Flag(\"encrypt-etcd-storage\").Changed {\n\t\t\t\toptions.EncryptEtcdStorage = &encryptEtcdStorage\n\t\t\t}\n\n\t\t\tif err := checkProjectFlag(cmd.Flag(\"project\").Changed, options.Project); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tif sshPublicKey != \"\" {\n\t\t\t\toptions.SSHPublicKeys, err = loadSSHPublicKeys(sshPublicKey)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"error reading SSH key file %q: %v\", sshPublicKey, err)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn RunCreateCluster(cmd.Context(), f, out, options)\n\t\t},\n\t}\n\n\tcmd.Flags().BoolVarP(&options.Yes, \"yes\", \"y\", options.Yes, \"Specify --yes to immediately create the cluster\")\n\tcmd.Flags().Var(&options.Target, \"target\", fmt.Sprintf(\"Valid targets: %q, %q. Set this flag to %q if you want kOps to generate terraform\", cloudup.TargetDirect, cloudup.TargetTerraform, cloudup.TargetTerraform))\n\tcmd.RegisterFlagCompletionFunc(\"target\", completeCreateClusterTarget(options))\n\n\t// Configuration / state location\n\tif featureflag.EnableSeparateConfigBase.Enabled() {\n\t\tcmd.Flags().StringVar(&options.ConfigBase, \"config-base\", options.ConfigBase, \"A cluster-readable location where we mirror configuration information, separate from the state store.  Allows for a state store that is not accessible from the cluster.\")\n\t\tcmd.RegisterFlagCompletionFunc(\"config-base\", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {\n\t\t\t// TODO complete vfs paths\n\t\t\treturn nil, cobra.ShellCompDirectiveNoFileComp\n\t\t})","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/create_cluster.go#L204-L240","documentation":"During `kops create cluster`, if --ssh-public-key was provided, loadSSHPublicKeys(sshPublicKey) is called to read and parse the key file; a read failure is wrapped as 'error reading SSH key file'. It means the file could not be opened or read from disk.","triggerScenarios":"Passing --ssh-public-key with a path that does not exist, is a directory, or lacks read permissions when building CreateClusterOptions before RunCreateCluster is invoked.","commonSituations":"Typo in the key path; using ~/.ssh/id_rsa (private key) instead of the .pub file; running in CI where the key file wasn't mounted; wrong HOME so ~ expansion fails.","solutions":["Verify the path passed to --ssh-public-key exists and points to a .pub public key file","Check file permissions (must be readable by the current user)","Use an absolute path in CI/containers where the working directory or HOME differs","Pass an empty value or omit the flag to skip SSH key loading"],"exampleFix":"// before\nkops create cluster --ssh-public-key ~/.ssh/id_rsa ...\n// after\nkops create cluster --ssh-public-key ~/.ssh/id_rsa.pub ...","handlingStrategy":"validation","validationCode":"func validateSSHPublicKey(path string) error {\n\tif path == \"\" { return nil }\n\tfi, err := os.Stat(path)\n\tif err != nil { return fmt.Errorf(\"ssh key not found: %w\", err) }\n\tif fi.IsDir() { return fmt.Errorf(\"%s is a directory\", path) }\n\tdata, err := os.ReadFile(path)\n\tif err != nil { return err }\n\tif !strings.HasPrefix(string(data), \"ssh-\") {\n\t\treturn fmt.Errorf(\"%s does not look like a public key\", path)\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass the .pub file, never the private key","Use absolute paths in scripts and CI","Check the file exists before running kops create cluster","Mount SSH keys into CI containers explicitly"],"tags":["cli","ssh","file-io"],"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"}