{"id":8483,"date":"2013-05-12T20:38:55","date_gmt":"2013-05-13T00:38:55","guid":{"rendered":"http:\/\/scruss.com\/blog\/?p=8483"},"modified":"2013-05-12T20:38:55","modified_gmt":"2013-05-13T00:38:55","slug":"clean-up-your-gnupg-keyring","status":"publish","type":"post","link":"https:\/\/scruss.com\/blog\/2013\/05\/12\/clean-up-your-gnupg-keyring\/","title":{"rendered":"clean up your GnuPG keyring"},"content":{"rendered":"<p>For reasons too annoying to explain, my <a href=\"http:\/\/www.gnupg.org\/\">GnuPG<\/a> keyring was huge. It was taking a long time to find keys, and most of them weren&#8217;t ones I&#8217;d use. So I wrote this little script that strips out all of the keys that aren&#8217;t<\/p>\n<ol style=\"list-style-type: lower-alpha;\">\n<li>yours, or<\/li>\n<li>signatories to your key.<\/li>\n<\/ol>\n<p>The script doesn&#8217;t actually delete any keys. It produces shell-compatible output that you can pipe or copy to a shell. Now my keyring file is less than 4% the size (or more precisely, 37\u00e2\u20ac\u00b0) of the size it was before.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\n# clean_keyring.sh - clean up all the excess keys\r\n\r\n# my key should probably be the first secret key listed\r\nmykey=$(gpg --list-secret-keys | grep '^sec' | cut -c 13-20 | head -1)\r\nif\r\n    &#x5B; -z $mykey ]\r\nthen\r\n    # exit if no key string\r\n    echo &quot;Can't get user's key ID&quot;\r\n    exit 1\r\nfi\r\n\r\n# all of the people who have signed my key\r\nmysigners=$(gpg --list-sigs $mykey | grep '^sig' | cut -c 14-21 | sort -u) \r\n\r\n# keep all of the signers, plus my key (if I haven't self-signed)\r\nkeepers=$(echo $mykey $mysigners | tr ' ' '&#92;&#48;12' | sort -u)\r\n\r\n# the keepers list in egrep syntax: ^(key|key|\u00e2\u20ac\u00a6)\r\nkeepers_egrep=$(echo $keepers | sed 's\/^\/^(\/; s\/$\/)\/; s\/ \/|\/g;')\r\n\r\n# show all the keepers as a comment so this script's output is shell-able\r\necho '# Keepers: ' $keepers\r\n\r\n# everyone who isn't on the keepers list is deleted\r\ndeleters=$(gpg --list-keys | grep '^pub'|  cut -c 13-20 | egrep -v ${keepers_egrep})\r\n\r\n# echo the command if there are any to delete\r\n# command is interactive\r\nif\r\n    &#x5B; -z $deleters ]\r\nthen\r\n    echo &quot;# Nothing to delete!&quot;\r\nelse\r\n    echo 'gpg --delete-keys' $deleters\r\nfi\r\n<\/pre>\n<p>Files:<\/p>\n<ul>\n<li><a href=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2013\/05\/clean_keyring.sh_.txt\">clean_keyring.sh<\/a> (SHA-1 checksum: 8c71dabca84c33201184fe348ae35310622d2be6)<\/li>\n<li><a href=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2013\/05\/clean_keyring.sh_.txt.asc\">clean_keyring.sh.txt<\/a> \u00e2\u20ac\u201d gpg signature.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>For reasons too annoying to explain, my GnuPG keyring was huge. It was taking a long time to find keys, and most of them weren&#8217;t ones I&#8217;d use. So I wrote this little script that strips out all of the keys that aren&#8217;t yours, or signatories to your key. The script doesn&#8217;t actually delete any [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[2],"tags":[1477,2664,2663,2666,270,2665],"class_list":["post-8483","post","type-post","status-publish","format-standard","hentry","category-goatee-stroking-musing-or-something","tag-bash","tag-gnupg","tag-gpg","tag-keyring","tag-linux","tag-pgp"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pQNZZ-2cP","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/8483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/comments?post=8483"}],"version-history":[{"count":4,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/8483\/revisions"}],"predecessor-version":[{"id":8489,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/8483\/revisions\/8489"}],"wp:attachment":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/media?parent=8483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/categories?post=8483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/tags?post=8483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}