Skip to content

Instantly share code, notes, and snippets.

@jcooklin
Last active December 3, 2015 00:29
Show Gist options
  • Save jcooklin/97685f3849dd4cb82996 to your computer and use it in GitHub Desktop.
Save jcooklin/97685f3849dd4cb82996 to your computer and use it in GitHub Desktop.
Creates a gpg signing key
#!/bin/bash
gpg_batch_config="/tmp/gpg-batch"
my_name="Joel Cooklin"
my_email="joel.r.cooklin@intel.com"
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
echo ""
echo "${green}Creating the following config file for creating a GPG signing key${reset}"
cat >$gpg_batch_config<<EOF
%echo Generating a default key
Key-Type: RSA
Key-Length: 2048
Subkey-Type: RSA
Subkey-Length: 2048
Name-Real: ${my_name}
Name-Comment: snap signing key
Name-Email: ${my_email}
Expire-Date: 0
Passphrase: snap
%pubring snap.pub
%secring snap.sec
%commit
%echo done
EOF
echo ""
cat $gpg_batch_config
echo ""
echo "[Enter] to continue"
read x
echo "${green}Generate the key using batch mode${reset}"
echo "${red}gpg --batch --gen-key gpg-batch${reset}"
echo ""
echo "[Enter] to continue"
read x
gpg --batch --gen-key $gpg_batch_config
echo ""
echo "${green}List the keys${reset}"
echo "${red}gpg --no-default-keyring --secret-keyring ./snap.sec --keyring ./snap.pub --list-keys${reset}"
echo ""
echo "[Enter] to continue"
read x
gpg --no-default-keyring --secret-keyring ./snap.sec --keyring ./snap.pub --list-keys
id=`gpg --no-default-keyring --secret-keyring ./snap.sec --keyring ./snap.pub --list-keys | grep pub | sed -n 's/^.*2048R\/\([A-Za-z0-9]*\).*$/\1/p'`
echo "${green}Trust the key we just created${reset}"
echo "${red}gpg --no-default-keyring --secret-keyring ./snap.sec --keyring ./snap.pub --edit-key ${id} trust${reset}"
echo ""
echo "[Enter] to continue"
read x
gpg --no-default-keyring --secret-keyring ./snap.sec --keyring ./snap.pub --edit-key ${id} trust
echo ""
echo "${green}Export the public key${reset}"
echo "${red}gpg --no-default-keyring --armor --secret-keyring ./snap.sec --keyring ./snap.pub --export ${my_email} > pubkeys.gpg${reset}"
echo ""
echo "[Enter] to continue"
read x
gpg --no-default-keyring --armor --secret-keyring ./snap.sec --keyring ./snap.pub --export ${my_email} > pubkeys.gpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment