Home Technology How to Fix “sign_and_send_pubkey: signing failed… agent refused operation” (GitHub SSH Error)

How to Fix “sign_and_send_pubkey: signing failed… agent refused operation” (GitHub SSH Error)

by karani

If you’re working with Git and suddenly hit this error:

sign_and_send_pubkey: signing failed for ED25519 "/home/user/.ssh/id_ed25519" from agent: agent refused operation git@github.com: Permission denied (publickey). fatal: Could not read from remote repository.

This means your SSH key is not being used correctly by your system or SSH agent.

This guide will walk you through fixing it step-by-step.

What Causes This Error?

This error typically happens when:

  • Your SSH key permissions are incorrect
  • The SSH agent is not running properly
  • The key is not loaded into the agent
  • GitHub does not have your public key
  • The wrong SSH key is being used

Step 1: Fix SSH Key Permissions

Run the following commands:

chmod 700 ~/.ssh chmod 600 ~/.ssh/id_ed25519 chmod 644 ~/.ssh/id_ed25519.pub

Why this matters:
SSH will refuse to use keys that are too open (for security reasons).

Step 2: Restart SSH Agent and Reload Key

Clear existing keys and start fresh:

ssh-add -D eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519

If you still see:

agent refused operation

Force restart:

pkill ssh-agent eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519

Step 3: Verify SSH Connection to GitHub

Test your connection:

ssh -T git@github.com

Expected output:

Hi username! You've successfully authenticated...

Step 4: Ensure Your SSH Key Is Added to GitHub

Check your public key:

cat ~/.ssh/id_ed25519.pub

Copy the output and add it to GitHub:

  • Go to GitHub → Settings → SSH and GPG Keys
  • Click New SSH Key
  • Paste your key

Step 5: Force Git to Use the Correct Key (Important)

If you have multiple SSH keys, Git might use the wrong one.

Create or edit this file:

nano ~/.ssh/config

Add:

Host github.com HostName github.com User git IdentityFile ~/.ssh/id_ed25519 IdentitiesOnly yes

Then save and exit.

Step 6: Test Again

ssh -T git@github.com

Then retry your Git command:

git pull # or git push

Full Fix Script (Quick Copy-Paste)

If you want a fast fix, run everything at once:

chmod 700 ~/.ssh chmod 600 ~/.ssh/id_ed25519 chmod 644 ~/.ssh/id_ed25519.pub pkill ssh-agent eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519 ssh -T git@github.com

Common Mistakes to Avoid

  • Using the wrong key file (id_rsa vs id_ed25519)
  • Not adding the key to GitHub
  • Forgetting to restart the SSH agent
  • Having multiple SSH keys without a config file

Pro Tip

If you frequently work across multiple GitHub accounts or servers, always use an SSH config file. It saves you hours of debugging.

Conclusion

This error is not a Git problem – it’s an SSH configuration issue.

Once you:

  • Fix permissions
  • Restart the agent
  • Load the key
  • Ensure GitHub has your public key

…everything works immediately.

You may also like