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:
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:
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:
Then add the key with keychain support:
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:
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:
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_workbut you loadedid_rsa, the prompt can continue because SSH is still trying other keys or falling back incorrectly. Hostentry does not match: If theHostline in~/.ssh/configdoes not match the actual remote host, options likeUseKeychainandIdentityFilenever 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.
Related reading
- Git keeps prompting me for a password
- git LaTeX workflow
- Git lfs - this exceeds GitHub's file size limit of 100.00 MB
- GIT list of new/modified/deleted files
- Git merge errors
- Git merge reports Already up-to-date though there is a difference
- Git list only untracked files also, custom commands
- git log --follow, the gitpython way
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo 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 courseInterview Questions practice on Codemia
Over 11,000 interview practice questions for 300+ companies, searchable by company and role.