Last active
September 6, 2022 09:11
-
-
Save worldofgeese/7eb999bfd0742ac801a02eff7e0d2d38 to your computer and use it in GitHub Desktop.
Script to generate gpg keys quickly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "This script generates GPG keys valid for 1 year for macOS, Linux, and WSL2 users automatically. The email attached to the resulting key will only be valid if you have an garden.io email domain with a local-part of your first name." | |
if [ "Darwin" = $(uname) ]; then | |
FULLNAME=$(id -P $USER | awk -F '[:]' '{print $8}') | |
EMAIL=$(id -P "$USER" | cut -d: -f5 | cut -d, -f1 | sed s/'\w*$'// | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]' | sed 's/$/@garden.io/') | |
else | |
FULLNAME=$(getent passwd $USER | cut -d: -f5 | cut -d, -f1) | |
EMAIL=$(getent passwd "$USER" | cut -d: -f5 | cut -d, -f1 | sed s/'\w*$'// | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]' | sed 's/$/@garden.io/') | |
fi | |
gpg --batch --passphrase '' \ | |
--quick-generate-key "$FULLNAME <$EMAIL>" ed25519 cert 1y | |
FPR=$(gpg --list-options show-only-fpr-mbox --list-secret-keys | awk '{print $1}') | |
gpg --batch --passphrase '' \ | |
--quick-add-key $FPR ed25519 sign 1y | |
gpg --batch --passphrase '' \ | |
--quick-add-key $FPR cv25519 encrypt 1y | |
gpg --batch --passphrase '' \ | |
--quick-add-key $FPR ed25519 auth 1y | |
sleep 1 | |
gpg --armor --export > $HOME/gpgpubkey.txt | |
echo "\ | |
unset SSH_AGENT_PID | |
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then | |
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)" | |
fi | |
export GPG_TTY=$(tty) | |
gpg-connect-agent updatestartuptty /bye >/dev/null" >> $HOME/.bashrc | |
source $HOME/.bashrc | |
gpg --export-ssh-key $EMAIL > $HOME/sshpubkey.txt | |
# Add auth subkey keygrip to sshcontrol | |
gpg --list-keys --with-keygrip | tail -2 | awk '{print $NF}' >> $HOME/.gnupg/sshcontrol | |
ssh-add -l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment