How GitHub knows who’s there
Everyone goes to one address — [email protected], and the user is always git. GitHub decides who arrived by the key:
an account key is the account with all its repositories, a deploy key is one repository. So different access on one
computer means different keys, and ~/.ssh/config picks the key through aliases:
git@github-infra:example-user/infra-web1.git → Host github-infra → key infra_deploy → one repository
[email protected]:example-user/notes.git → Host github.com → id_ed25519 → personal account
git@github-work:work-org/app.git → Host github-work → id_work → work account
A deploy key: the server sees one repository
A server running git pull in /opt (Server configs in git) needs to read its own repository — and only that. A
personal account key would open every repository, and if the server were compromised, all of them at once
(Each key and token grants one access).
Create a key on the server
sudo ssh-keygen -t ed25519 -f /root/.ssh/infra_deploy -C "deploy web1 infra-web1" -N ""No passphrase (
-N ""):git pullruns without a person. That’s acceptable because the key opens one repository, and it doesn’t need write access. The key belongs to root because root owns/opt.Add it to the repository
sudo cat /root/.ssh/infra_deploy.pub # ssh-ed25519 AAAAC3Nza… deploy web1 infra-web1On GitHub: the repository, Settings, Deploy keys, Add deploy key. Enable “Allow write access” only if the server will
push; under the rule “onlygit pullon the server”, leave it off.An alias in root’s ~/.ssh/config
# /root/.ssh/config Host github-infra HostName github.com User git IdentityFile /root/.ssh/infra_deploy IdentitiesOnly yesCheck the login: for a deploy key GitHub greets you with the repository name:
sudo ssh -T github-infra # Hi example-user/infra-web1! You've successfully authenticated, but GitHub does not provide shell access.The repository URL — through the alias
cd /opt sudo git remote set-url origin git@github-infra:example-user/infra-web1.git sudo git pull
Two accounts on one computer
A second key — for the work account
ssh-keygen -t ed25519 -f ~/.ssh/id_work -C "work laptop-2026"Add the
.pubto the work GitHub account (Settings, SSH and GPG keys).An alias
# ~/.ssh/config — above the Host * block Host github-work HostName github.com User git IdentityFile ~/.ssh/id_work IdentitiesOnly yes Host github.com IdentityFile ~/.ssh/id_ed25519 IdentitiesOnly yesIdentitiesOnly yeson both: otherwise the agent offers the first matching key, and GitHub lets you in as the wrong account.Work repositories — through the alias and with their own email
git clone git@github-work:work-org/app.git ~/work/appThe email for every repository under
~/work/comes throughincludeIfin~/.gitconfig(~/.gitconfig block by block):# ~/.gitconfig-work [user] email = [email protected]
Signing commits with an SSH key
Since git 2.34, commits can be signed with an SSH key; no GPG needed. GitHub marks such commits “Verified”: the commit
was made by the key’s owner, not by someone who typed another person’s name into user.name.
Turn on signing
git config --global gpg.format ssh git config --global user.signingKey ~/.ssh/id_ed25519.pub git config --global commit.gpgSign true git config --global tag.gpgSign trueuser.signingKeyis the path to the public half: the agent signs with the private one (ssh-agent), so the passphrase isn’t asked a second time.The signing key — into GitHub
Settings, SSH and GPG keys, New SSH key, type Signing Key. The same
.pubyou use to log in, but as a separate entry: a login key doesn’t verify signatures.Verifying signatures locally
Without a list of trusted keys,
git log --show-signatureprintserror: gpg.ssh.allowedSignersFile needs to be configured and exist for ssh signature verificationandNo signature, even though there is one. The list lives in a file:mkdir -p ~/.config/git echo "[email protected] namespaces=\"git\" $(cat ~/.ssh/id_ed25519.pub)" \ >> ~/.config/git/allowed_signers git config --global gpg.ssh.allowedSignersFile ~/.config/git/allowed_signers
If it doesn’t work
ERROR: The key you are authenticating with has been marked as read only.
- Cause
- The deploy key was added without “Allow write access”, and the server runs
git push. - Fix
- That’s by design if the server only reads. If it must push, enable write access for this key in the repository settings.
GitHub won’t accept a key: Key is already in use
- Cause
- One key is one deploy key for one repository, or one account’s key. GitHub won’t take it twice.
- Fix
- For a second repository, a separate key and a separate alias in
~/.ssh/config.
The push goes as the wrong account: Permission to work-org/app.git denied to example-user
- Cause
sshoffered the first matching key — the personal one. GitHub identifies the account by the key, not the URL.- Fix
- A
github-workalias withIdentityFileandIdentitiesOnly yes, and the repository URL through it:git remote set-url origin git@github-work:work-org/app.git.
Commits on GitHub show someone else’s name or no avatar
- Cause
- The commit has an email that isn’t on the account: the work repository still has the personal one, or the other way round.
- Fix
includeIfwith a different email for~/work/(~/.gitconfig block by block); check withgit config user.emailinside the repository.
error: gpg failed to sign the data
- Cause
- Signing is on (
commit.gpgSign), but the format is stillopenpgp: git looks forgpgand a GPG key. - Fix
git config --global gpg.format ssh, anduser.signingKeyset to the path of the.pub.
Signed commits show “Unverified” on GitHub
- Cause
- The key was added to GitHub as a login key (Authentication), and signing needs a separate Signing Key entry. Or the commit email isn’t verified on the account.
- Fix
- Settings, SSH and GPG keys, New SSH key, type Signing Key — the same
.pub.
How to check
Each alias leads to its own account:
ssh -T [email protected]
# Hi example-user! You've successfully authenticated, but GitHub does not provide shell access.
ssh -T github-work
# Hi work-user! You've successfully authenticated, but GitHub does not provide shell access.
The last commit is signed:
git log --show-signature -1 --format='%h %s'
# Good "git" signature for [email protected] with ED25519 key SHA256:u7WT…
# 3e2d1c traefik: readTimeout 300s