Git keeps asking me for my ssh key passphrase
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
If Git keeps asking for your SSH key passphrase, the most likely reason is simple: your private key is encrypted, but nothing is caching the unlocked key between commands. That is normal security behavior, not a Git bug. The fix is usually to load the key into ssh-agent or your OS keychain so Git can reuse it without prompting every time.
Why the Prompt Keeps Appearing
When Git talks to a remote over SSH, it delegates authentication to your SSH client. If your private key is protected with a passphrase, the SSH client must unlock it before it can authenticate.
Without an agent, this can happen on every git pull, git push, or git fetch.
You can confirm the remote is using SSH with:
If the remote looks like [email protected]:owner/repo.git, Git is using SSH. If it looks like https://..., your problem is different.
Load the Key into ssh-agent
On macOS and Linux, the usual fix is to start ssh-agent and add your key once per login session.
Use your real private key path if it is not id_ed25519.
After adding the key, test SSH authentication directly:
If the agent is working, Git operations should stop asking for the passphrase repeatedly during that session.
macOS Keychain Integration
On macOS, you can make this smoother by telling SSH to store the passphrase in the keychain and auto-add the key to the agent.
In ~/.ssh/config:
Then add the key with keychain support:
This is usually the most convenient setup for a Mac development machine because the passphrase survives terminal restarts without removing the key’s protection.
Linux and Other Unix-Like Systems
On Linux, desktop environments often start an SSH agent automatically. If not, starting it manually and adding the key is enough for most shell-based workflows.
You can inspect loaded keys with:
If that command reports no identities, the agent is running but your key is not loaded yet.
If it says it cannot connect to the authentication agent, the agent environment variables are missing and you need to start or reattach to the agent.
Windows Notes
On Windows, the OpenSSH Authentication Agent service can store the unlocked key for you. After starting the agent, add the key with:
If you use Git tools that bundle their own SSH client, make sure they are using the same agent and key paths you expect.
Do Not "Fix" It by Removing the Passphrase Unless You Mean To
It is possible to remove the passphrase from a key, but that is a security tradeoff, not a convenience setting. A passphrase protects the key if the private key file is copied or your machine is compromised at rest.
If convenience is the goal, using an agent or keychain is usually the better solution.
Common Pitfalls
One common problem is adding the wrong key. If your Git host is expecting ~/.ssh/id_ed25519_work but you loaded id_rsa, the prompt may continue because SSH is still trying several keys or falling back incorrectly.
Another issue is missing or overly broad SSH config. If the Host entry does not match the actual remote host, options like UseKeychain and IdentityFile may never apply.
Permissions can also matter. Private keys should not be world-readable. If SSH refuses to use the key, fix permissions with something like chmod 600 ~/.ssh/id_ed25519.
Finally, some developers accidentally use HTTPS remotes in one repository and SSH remotes in another, then assume one fix should cover both.
Summary
- Repeated passphrase prompts usually mean your SSH key is encrypted and not cached by an agent.
- Start
ssh-agentand add the key withssh-add. - On macOS,
UseKeychain yesandAddKeysToAgent yesmake the workflow smoother. - Verify that your Git remote is actually using SSH and that the correct key is loaded.
- Prefer using an agent or keychain over removing the passphrase from the private key.
Related reading
- Git keeps asking me for my ssh key passphrase
- Git keeps prompting me for a password
- Git keeps prompting me for a password
- git LaTeX workflow
- Git merge errors
- Git merge reports Already up-to-date though there is a difference
- Git lfs - this exceeds GitHub's file size limit of 100.00 MB
- GIT list of new/modified/deleted files
.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 courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.