sign_and_send_pubkey: signing failed: agent refused operation (SSH) — how to fix
sign_and_send_pubkey: signing failed for ED25519 "/home/me/.ssh/id_ed25519" from agent: agent refused operation
git@github.com: Permission denied (publickey).
Quick fix: Fix key permissions: chmod 600 ~/.ssh/id_ed25519 and chmod 700 ~/.ssh. Then reload the key into the agent: ssh-add -D && ssh-add ~/.ssh/id_ed25519. With gpg-agent run gpg-connect-agent updatestartuptty /bye. Test with ssh -T git@github.com.
What it means
When an SSH agent is running (SSH_AUTH_SOCK is set), ssh doesn't read your private key itself. It asks the agent to sign the login. If the agent refuses, ssh falls back to the other methods and usually ends with Permission denied (publickey).
See which agent you're talking to and which keys it holds:
echo "$SSH_AUTH_SOCK"
ssh-add -l
A socket under /run/user/<uid>/keyring/ belongs to GNOME Keyring, one under /run/user/<uid>/gnupg/ belongs to gpg-agent, and /tmp/ssh-XXXX/agent.N is a plain ssh-agent.
Run ssh with -v to see the attempt in detail:
ssh -v git@github.com 2>&1 | grep -iE "offering|sign|agent"
Cause 1: the private key file has wrong permissions
Some agents re-read the key file and refuse to use it when it's readable by other users. This often happens after copying keys from another machine or a backup.
Fix:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519 ~/.ssh/id_rsa 2>/dev/null
chmod 644 ~/.ssh/*.pub
ssh-add -D # forget cached keys
ssh-add ~/.ssh/id_ed25519
Cause 2: the agent couldn't ask for the passphrase or confirmation
The agent has the key listed, but needs to unlock it or confirm its use, and no prompt can be shown, for example in an SSH session on a remote host, a TTY without a desktop, or a container.
gpg-agent as SSH agent: tell it which terminal to use for pinentry:
gpg-connect-agent updatestartuptty /bye
Add export GPG_TTY=$(tty) to your shell profile so pinentry knows the terminal.
Key added with confirmation (ssh-add -c): each use needs an ssh-askpass dialog. Install one (sudo apt install ssh-askpass) or re-add the key without -c.
GNOME Keyring: unlock the keyring (log in to the desktop session), or skip it by starting your own agent in that shell:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Cause 3: a hardware security key wasn't touched
For FIDO keys (id_ed25519_sk, id_ecdsa_sk) and smart cards, the agent refuses when the device isn't plugged in, isn't touched in time, or the PIN prompt fails. Plug it in, run the command again and touch the key when it blinks.
Cause 4: stale agent after changing or regenerating keys
If you replaced a key file with a new one under the same name, the agent may still hold the old identity. Clear and re-add:
ssh-add -D
ssh-add ~/.ssh/id_ed25519
ssh-add -l # check the fingerprint matches: ssh-keygen -lf ~/.ssh/id_ed25519.pub
Workaround: bypass the agent
To confirm the key itself is fine, tell ssh to read the file directly and ignore the agent:
SSH_AUTH_SOCK= ssh -i ~/.ssh/id_ed25519 -o IdentitiesOnly=yes -T git@github.com
If that works, the problem is only the agent. Fix it with the steps above, or pin the key in ~/.ssh/config:
Host github.com
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
Last updated 2026-12-04.