{"record":{"id":"6345c8b3b38ae108","repo":"cli/cli","slug":"unable-to-delete-gpg-key-s-either-the-gpg-key-is","errorCode":null,"errorMessage":"unable to delete GPG key %s: either the GPG key is not found or it is not owned by you","messagePattern":"unable to delete GPG key (.+?): either the GPG key is not found or it is not owned by you","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cmd/gpg-key/delete/delete.go","lineNumber":83,"sourceCode":"\t\treturn err\n\t}\n\n\thost, _ := cfg.Authentication().DefaultHost()\n\tgpgKeys, err := getGPGKeys(httpClient, host)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tid := \"\"\n\tfor _, gpgKey := range gpgKeys {\n\t\tif gpgKey.KeyID == opts.KeyID {\n\t\t\tid = strconv.FormatInt(gpgKey.ID, 10)\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif id == \"\" {\n\t\treturn fmt.Errorf(\"unable to delete GPG key %s: either the GPG key is not found or it is not owned by you\", opts.KeyID)\n\t}\n\n\tif !opts.Confirmed {\n\t\tif err := opts.Prompter.ConfirmDeletion(opts.KeyID); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\terr = deleteGPGKey(httpClient, host, id)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif opts.IO.IsStdoutTTY() {\n\t\tcs := opts.IO.ColorScheme()\n\t\tfmt.Fprintf(opts.IO.Out, \"%s GPG key %s deleted from your account\\n\", cs.SuccessIcon(), opts.KeyID)\n\t}\n","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/cli/cli/blob/0eeec0b92edbe70199f9768522f831d3534f41ad/pkg/cmd/gpg-key/delete/delete.go#L65-L101","documentation":"Thrown by gh gpg-key delete after it listed all GPG keys on the account and found none whose KeyID equals --key-id. The deletion endpoint needs the database ID, so a miss on the local lookup produces this combined not-found/not-yours message before any API mutation is attempted.","triggerScenarios":"`gh gpg-key delete ABC1234D` with a mistyped or wrong-case key ID, a key uploaded to a different account/host, or a key already removed. The comparison is against the short/long key IDs returned by the list API.","commonSituations":"Using the fingerprint instead of the key ID, using the key ID from a work account against a personal GH_HOST, or repeating a delete that already succeeded.","solutions":["List your keys and copy the exact ID: `gh gpg-key list`.","Confirm you are on the right host/account: `gh auth status`; switch with `gh auth switch`.","If the key is already absent, no action is needed; the delete goal is already met."],"exampleFix":"# before\ngh gpg-key delete \"4CAE 5D6F ...\"   # fingerprint passed\n# gh: unable to delete GPG key ...: either the GPG key is not found or it is not owned by you\n\n# after\ngh gpg-key list                      # shows KeyID 3AA5C34371567BD2\ngh gpg-key delete 3AA5C34371567BD2","handlingStrategy":"validation","validationCode":"// Resolve the key against the account list before deleting:\nkeys, err := getGPGKeys(httpClient, host)\nif err != nil { return err }\nfound := false\nfor _, k := range keys {\n\tif k.KeyID == opts.KeyID { found = true; break }\n}\nif !found {\n\t// print available KeyIDs so the user can correct the argument\n\treturn fmt.Errorf(\"key %s not in account; run `gh gpg-key list`\", opts.KeyID)\n}","typeGuard":"func keyExists(keys []gpgKey, keyID string) bool {\n\tfor _, k := range keys {\n\t\tif k.KeyID == keyID { return true }\n\t}\n\treturn false\n}","tryCatchPattern":"if err := deleteRun(opts); err != nil {\n\tif strings.Contains(err.Error(), \"unable to delete GPG key\") {\n\t\t// run `gh gpg-key list`, compare KeyIDs exactly, retry or treat as already-deleted\n\t}\n}","preventionTips":["Always copy the KeyID from `gh gpg-key list`, not from gpg --list-keys fingerprints.","Confirm host/account with `gh auth status` before deleting.","Treat 'already removed' as success in idempotent cleanup scripts."],"tags":["gpg-key","delete","not-found","authentication"],"backgroundTag":null,"analyzedSha":"0eeec0b92edbe70199f9768522f831d3534f41ad","analyzedAt":"2026-08-15T12:31:05.478Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}