Skip to content

Instantly share code, notes, and snippets.

@wes-goulet
Last active September 26, 2022 23:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wes-goulet/59e1a9961f8b42613fd9d06f5e651204 to your computer and use it in GitHub Desktop.
Save wes-goulet/59e1a9961f8b42613fd9d06f5e651204 to your computer and use it in GitHub Desktop.
Commands to import and setup your gpg key for git commit signing
# install gpg
brew install gnupg
# copy my-gpg-key.asc from other workstation or lastpass or somewhere
# and then import it
gpg --import ~/Downloads/my-gpg-key.asc
# make sure it's there and get the key id (the part that comes after "rsa4096/")
gpg --list-secret-keys --keyid-format LONG
gpg --edit-key <key ID>
# then use the "trust" command to give your key ultimate trust - CTRL-D to exit gpg
# now tell git to use your key
git config --global user.signingkey <key ID>
git config --global commit.gpgsign true
git config --global push.gpgsign if-asked
git config --global gpg.program $(which gpg)
@wes-goulet
Copy link
Author

wes-goulet commented Dec 5, 2019

you also need to add the following to your .bash_profile

# be sure to add these 2 lines to your bash profile otherwise gpg git
# commit signing will say "failed to sign the data"
GPG_TTY=$(tty)
export GPG_TTY

@Jingsong-Chen
Copy link

Jingsong-Chen commented Mar 18, 2022

If you are not using bash try adding the above lines to your ~/.zshrc then run source ~/.zshrc
I also feel that VPN and TMP Auth are required?
Also, the following block saved me multiple times:
if [ -r ~/.bash_profile ]; then echo 'export GPG_TTY=$(tty)' >> ~/.bash_profile; \ else echo 'export GPG_TTY=$(tty)' >> ~/.profile; fi

@wes-goulet
Copy link
Author

wes-goulet commented Sep 26, 2022

To export the GPG public key use the following command:

gpg --armor --export <key ID>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment