Skip to content

Instantly share code, notes, and snippets.

@Someguy123
Created June 2, 2021 13:28
Show Gist options
  • Save Someguy123/d97d6913691839948fbbaeb2fb06a198 to your computer and use it in GitHub Desktop.
Save Someguy123/d97d6913691839948fbbaeb2fb06a198 to your computer and use it in GitHub Desktop.
Bash/ZSH function - Enables you to upload one or more GPG / PGP public keys to multiple keyservers in one command.
##################
#
# This is a ZSH/Bash function that helps you to quickly publish one or more GPG keys to
# several keyservers using just one command.
#
# Add the below code to your ~/.bashrc or ~/.zshrc (or put it in a separate file, if you
# understand how and why to source files - whatever you prefer).
#
# You can use it like so:
#
# upload-keys ABCD1234DEFA5632 DEFA123A56236
#
# That would upload both of those keys, to all keyservers listed in the 'keyservers'
# variable, and display progress info as it does so.
#
# You can use it to publish just a single key, or 100 keys - just pass each
# key id / fingerprint you want to publish as an argument to the function.
#
# This function was created by Someguy123 (github.com/Someguy123 | www.privex.io)
#
# I (Someguy123) also wrote the list of keyservers, effectively in priority order,
# with keys.openpgp.org generally being the biggest keyserver, and used by default
# by most clients - while almost nothing uses pgp.cyberbits.eu (that i'm aware of).
#
##################
keyservers=(
hkps://keys.openpgp.org
hkps://keyserver.ubuntu.com
hkps://gpg.privex.io
hkps://pgpkeys.mit.edu
hkps://pgp.surf.nl
hkp://pgp.cyberbits.eu
)
upload-keys() {
echo -e " >> Going to upload the following keys:"
for xkey in "$@"; do
echo -e " $xkey"
done
sleep 2
for xkey in "$@"; do
echo -e "\n\n---------\n Uploading GPG key: $xkey \n---------\n"
for ks in "${keyservers[@]}"; do
echo -e " $ks <- $xkey";
gpg --keyserver "$ks" --send-keys "$xkey";
done
done
echo -e "\n\n---------\n FINISHED UPLOADING $# KEYS :) \n---------\n"
}
##########
# Generally you'd only really need to publish to the top 4 in gpg-upload-key.sh, as it includes
# two lesser-known servers that are unlikely to be used regularly these days.
#
# But, if you REALLY want to publish to as many keyservers as possible, here's an extended
# keyserver list to help you propagate your key across the world :)
#
# The keyservers in this file were found and accumulated by Someguy123 (github.com/Someguy123 | www.privex.io)
#
#########
keyservers=(
hkps://keys.openpgp.org hkps://gpg.privex.io hkps://keyserver.ubuntu.com
hkps://keyring.debian.org hkp://pgp.cyberbits.eu hkp://pgpkeys.mit.edu
hkps://pgp.surf.nl hkps://pgp.uni-mainz.de hkps://keyserver.insect.com
hkps://sks.pod01.fleetstreetops.com hkps://keyserver-03.2ndquadrant.com
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment