brew install gpg2 gnupg pinentry-macWith pinentry-mac you will be able to enter your password in a popup window instead of the terminal.
mkdir ~/.gnupgecho "pinentry-program $(brew --prefix)/bin/pinentry-mac" > ~/.gnupg/gpg-agent.confecho "use-agent" >> ~/.gnupg/gpg.confAppend the following to your ~/.bash_profile or ~/.bashrc or ~/.zshrc
For instance
echo "export GPG_TTY=$(tty)" >> ~/.zshrc# on the built-in bash on macos usesource ~/.bash_profile# if using bash through homebrew over ssh usesource ~/.bashrc# and if using zshsource ~/.zshrcchmod 700 ~/.gnupg/*killall gpg-agentgpg --full-gen-key --pinentry-mode loopbackPlease select what kind of key you want: (1) RSA and RSA (default) (2) DSA and Elgamal (3) DSA (sign only) (4) RSA (sign only)Your selection? 4RSA keys may be between 1024 and 4096 bits long.What keysize do you want? (2048) 4096Requested keysize is 4096 bitsPlease specify how long the key should be valid. 0 = key does not expire <n> = key expires in n days <n>w = key expires in n weeks <n>m = key expires in n months <n>y = key expires in n yearsKey is valid for? (0) 0Key does not expire at allIs this correct? (y/N) y
You need a user ID to identify your key; the software constructs the user IDfrom the Real Name, Comment and Email Address in this form: "Su Ho (S) <hi@suho.dev>"
Real name: Su HoEmail address: hi@suho.devComment:You selected this USER-ID: "Su Ho <hi@suho.dev>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? oYou need a Passphrase to protect your secret key.gpg --list-secret-keys --keyid-format SHORTThis command will generate an output similar to this:
/Users/suho/.gnupg/pubring.kbx------------------------------sec ed25519/XXXXXXXX 2023-11-29 [SC]...You will need to copy the key ID, in this case XXXXXXXX.
gpg --armor --export XXXXXXXXgit config --global user.signingkey XXXXXXXXgit config --global commit.gpgsign truegit commit -S -s -m "Signed Commit" --allow-emptyYou should see a popup window asking for your password. Enter your password and click OK.
gpg --armor --export XXXXXXXX | pbcopyThen login into github.com and go to your settings, SSH and GPG Keys, and add your GPG key from the page.
Follow this guide for more details.