Skip to content

How to Fix Git SSH Key Not Working Error

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Git SSH Key Not Working Error. We cover key concepts, practical examples, and best practices.

You try to clone or push using SSH and get Permission denied (publickey) — your SSH key is not configured, not added to the SSH agent, or not registered with your Git hosting provider.

The Problem

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Step-by-Step Fix

Step 1: Check existing SSH keys

ls -la ~/.ssh/

Look for id_ed25519 or id_rsa files.

Step 2: Generate a new SSH key (if none exists)

ssh-keygen -t ed25519 -C "your-email@example.com"

Accept the default location and set a passphrase (optional).

Step 3: Start the SSH agent and add the key

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

Step 4: Copy the public key

cat ~/.ssh/id_ed25519.pub

Step 5: Add the key to GitHub

  1. Go to GitHub.com → Settings → SSH and GPG keys → New SSH key
  2. Paste the public key content
  3. Save

Step 6: Test the connection

ssh -T git@github.com

Expected:

Hi username! You've successfully authenticated, but GitHub does not provide shell access.

Step 7: Configure Git to use SSH

git remote set-url origin git@github.com:user/repo.git

Step 8: Use SSH config for multiple keys

Create ~/.ssh/config:

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

Host gitlab.com
  HostName gitlab.com
  User git
  IdentityFile ~/.ssh/gitlab-key

Prevention Tips

  • Use Ed25519 keys instead of RSA (more secure and faster)
  • Add keys to SSH agent automatically in ~/.bashrc
  • Register keys with all Git providers you use
  • Back up your SSH keys securely
  • Use different keys for different services if needed

Common Mistakes with ssh key error

  1. Using foldl instead of foldl' causing stack overflow on large lists
  2. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  3. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable

These mistakes appear frequently in real-world GIT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does SSH ask for a passphrase every time?

The key was generated with a passphrase and is not added to the SSH agent. Run ssh-add ~/.ssh/id_ed25519 once. Or configure the agent in ~/.bashrc with eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_ed25519.

What is the difference between id_rsa and id_ed25519?

id_rsa uses RSA encryption (2048-4096 bits). id_ed25519 uses Ed25519 (smaller, faster, same security level). Ed25519 is recommended for new keys. Generate with ssh-keygen -t ed25519.

How do I debug SSH connection issues?

Run ssh -vT git@github.com for verbose output. Look for which keys are offered and the server's response. Common issues: wrong key permissions (must be 600), wrong remote URL, key not added to Git provider.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro