kubernetes/kops · warning
no SSH public key found
Error message
no SSH public key found
What it means
When `kops get sshpublickeys` renders in table mode (the default) and zero SSH public keys exist in the credential store, the command deliberately returns "no SSH public key found" instead of printing an empty table. It is an empty-result condition surfaced as an error.
Source
Thrown at cmd/kops/get_sshpublickeys.go:112
for _, key := range l {
id, err := sshcredentials.Fingerprint(key.Spec.PublicKey)
if err != nil {
klog.Warningf("unable to compute fingerprint for public key")
}
item := &SSHKeyItem{
ID: id,
PublicKey: key.Spec.PublicKey,
}
items = append(items, item)
}
switch options.Output {
case OutputTable:
if len(items) == 0 {
return fmt.Errorf("no SSH public key found")
}
t := &tables.Table{}
t.AddColumn("ID", func(i *SSHKeyItem) string {
return i.ID
})
return t.Render(items, out, "ID")
case OutputYaml:
y, err := yaml.Marshal(items)
if err != nil {
return fmt.Errorf("unable to marshal YAML: %v", err)
}
if _, err := out.Write(y); err != nil {
return fmt.Errorf("error writing to output: %v", err)
}
case OutputJSON:
j, err := json.Marshal(items)
if err != nil {View on GitHub (pinned to 4c8573c808)
Solutions
- Add a key first: `kops create sshpublickey <cluster> -i ~/.ssh/id_rsa.pub` then re-run get
- Confirm --state/--name point at the store you expect (you may be looking at an empty one)
- In scripts, treat empty results gracefully by using `-o json` or `-o yaml`, which return an empty list instead of this error
Example fix
// before kops get sshpublickeys # errors when empty in table mode // after kops get sshpublickeys -o json | jq 'if length == 0 then "no keys" else . end'
Defensive patterns
Strategy: fallback
Validate before calling
count=$(kops get sshpublickeys -o json 2>/dev/null | jq 'length')
if [ "${count:-0}" -eq 0 ]; then echo 'no SSH public keys; add one with kops create sshpublickey'; fi Try / catch
out, err := runGetSSHPublicKeys(opts)
if err != nil && err.Error() == "no SSH public key found" {
// treat as empty result, not a failure
return nil
}
return err Prevention
- Use -o json or -o yaml when scripting; they do not error on empty results
- Add a key with `kops create sshpublickey` before dependent steps
- Double-check --state/--name to make sure you are querying the intended (non-empty) store
When it happens
Trigger: `kops get sshpublickeys` (or with -o table) against a cluster/state store that has never had a key added via `kops create sshpublickey`, or after all keys were deleted.
Common situations: Fresh state store; wrong --state or cluster name pointing at an empty store; key deleted by another operator; CI expecting keys before `kops update` adds them.
Related errors
- must specify %q label with cluster name to create SSHCredent
- spec.PublicKey is required
- error reading SSH key file %q: %v
- error reading SSH public key files %q: %v
- error adding SSH public key: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/e2cbaf57a72f0e61.
Report an issue: GitHub.