Last active
January 6, 2025 09:19
-
-
Save saumas/a8a752b07a2182876dd8684f54b856a2 to your computer and use it in GitHub Desktop.
Configure a new GPG key for signing your commits
This file contains hidden or 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
# Generate a new key. Suggestion is to use RSA 4096. Enter your name and email when prompted. | |
gpg --full-gen-key | |
# Get the ID of the generated key | |
GPG_KEY_ID=$(gpg --list-secret-keys --keyid-format LONG "[email protected]" | awk '/^sec/ {split($2, a, "/"); print a[2]}') | |
# Export the key which you will need to copy to your user settings in your repository (GitHub, GitLab, etc.) | |
gpg --armor --export $GPG_KEY_ID | |
# Tell git you want to sign all of your commits from now on. If you always use the same user, then use `--global` instead of `--local`. | |
git config --global commit.gpgsign true | |
git config --local user.name "Your Name" | |
git config --local user.email "[email protected]" | |
git config --local user.signingkey $GPG_KEY_ID | |
# If your terminal complains about bad terminal when committing, be sure to add this to your terminal run configuration: | |
export GPG_TTY=$(tty) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment