This guide sets up SSH for GitHub access and enables signed Git commits using your SSH key.
If you don't have one yet:
ssh-keygen -t ed25519 -C "[email protected]"
This creates
~/.ssh/id_ed25519
and~/.ssh/id_ed25519.pub
.
- Copy the public key:
cat ~/.ssh/id_ed25519.pub
-
Go to GitHub β Settings β SSH and GPG keys β New SSH key
-
Paste the key and save.
Start the SSH agent and add your key:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Optional: Add to ~/.ssh/config
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
ssh -T [email protected]
You should see:
Hi username! You've successfully authenticated...
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub
git config --global commit.gpgsign true
mkdir -p ~/.config/git
Add this to ~/.config/git/allowed_signers
:
[email protected] ssh-ed25519 AAAAC3... (from your .pub file)
Then:
git config --global gpg.ssh.allowedSignersFile ~/.config/git/allowed_signers
git commit --allow-empty -m "Test signed commit"
git log --show-signature
You should see something like:
gpg: Good signature from "[email protected]"
GitHub will show a β Verified badge if everything is set up right.
- GitHub only verifies commits signed with keys added in your SSH settings.
ed25519
keys are preferred overrsa
.- You can use a separate key just for signing if you want.
That's it! You're all set with SSH auth + commit signing. π