Git
SSH Key
Passphrase
Troubleshooting
Coding Issues

Git keeps asking for my SSH key passphrase

Codemia Knowledge Hub ·

Git keeps asking for your SSH key passphrase because the private key is encrypted and nothing is caching the unlocked key between commands. That is normal security behavior, not a Git bug. Load the key into ssh-agent or your OS keychain and Git can reuse it without prompting.

Why the prompt keeps appearing

Git hands SSH authentication to your SSH client. If the private key has a passphrase, the client has to unlock it before it can authenticate, and without an agent that can happen on every git pull, git push or git fetch.

First confirm the remote actually uses SSH:

bash
git remote -v

A remote like [email protected]:owner/repo.git uses SSH. One that starts with https://... has a different problem. Repositories can differ, so a fix for an SSH remote will not cover an HTTPS remote in another repository.

Load the key into ssh-agent

On macOS and Linux, start ssh-agent and add your key once per login session:

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

Use your real private key path if it is not id_ed25519. Then test SSH authentication directly:

With the agent working, Git stops asking for the passphrase for the rest of that session.

macOS: store the passphrase in the keychain

On macOS you can have SSH keep the passphrase in the keychain and add the key to the agent automatically. In ~/.ssh/config:

sshconfig
1Host github.com
2    AddKeysToAgent yes
3    UseKeychain yes
4    IdentityFile ~/.ssh/id_ed25519

Then add the key with keychain support:

bash
ssh-add --apple-use-keychain ~/.ssh/id_ed25519

This is usually the most convenient setup on a Mac: the passphrase survives terminal restarts and the key stays protected.

Linux: check whether the agent has your key

Desktop environments on Linux often start an SSH agent automatically. If yours does not, starting it manually and adding the key is enough for most shell workflows.

List the loaded keys:

bash
ssh-add -l

If it reports no identities, the agent is running but your key is not loaded. If it cannot connect to the authentication agent, the agent's environment variables are missing and you need to start or reattach to the agent.

Windows: use the OpenSSH Authentication Agent

The OpenSSH Authentication Agent service can hold the unlocked key. After starting it, add the key:

powershell
ssh-add $HOME\.ssh\id_ed25519

Git tools that bundle their own SSH client may not use the same agent, so check that they point at the agent and key paths you expect.

Still prompted after adding the key

  • Wrong key loaded: If your Git host expects ~/.ssh/id_ed25519_work but you loaded id_rsa, the prompt can continue because SSH is still trying other keys or falling back incorrectly.
  • Host entry does not match: If the Host line in ~/.ssh/config does not match the actual remote host, options like UseKeychain and IdentityFile never apply.
  • Permissions: Private keys must not be world-readable. If SSH refuses the key, fix permissions with something like chmod 600 ~/.ssh/id_ed25519.

Removing the passphrase is a security tradeoff

You can strip the passphrase from a key, but that trades security for convenience. The passphrase protects the key if the file is copied or the machine is compromised at rest. If convenience is the goal, an agent or keychain is the better fix.


Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Interview Questions practice on Codemia

Over 11,000 interview practice questions for 300+ companies, searchable by company and role.

Browse interview questions