git pull from Bitbucket Cloud over SSH is refused with a publickey error
Permission denied (publickey).Short answer
Bitbucket Cloud ended the SSH login because none of the keys your machine offered matches a key saved on your Bitbucket account. Run ssh -T -vvv and read which key was tried. The usual reasons: the public key was never added, the agent does not hold it, another account's key goes first, an RSA SHA-1 key, loose file modes, or an unconverted PuTTY key.
Fix it fast
1Find out which cause you have
Test the SSH login on its own, without Git, and keep the verbose output. A working setup ends by saying you are authenticated via ssh key and that shell access is disabled. A broken one ends with Permission denied (publickey). Use the host name that git remote -v shows.
git remote -v ssh -T -vvv git@ssh.bitbucket.org2Match what you see, then jump to its fix
- 1
The login ends with Permission denied (publickey) and the SSH keys page in your Bitbucket settings is empty or lists some other key.The public key was never added to your Bitbucket accountFix - 2
The verbose output lists identity files, but the key you added to Bitbucket is not among the ones tried.The SSH agent does not hold the key, or offers other keys firstFix - 3
The message is The requested repository either does not exist or you do not have access, followed by fatal: Could not read from remote repository, although the repository is yours.You use more than one Bitbucket account and the other account's key goes firstFix - 4
The verbose output has the line debug1: send_pubkey_test: no mutual signature algorithm.An older RSA key whose SHA-1 signature is no longer acceptedFix - 5
The key is on your account and on disk, yet it is never used; ls -l shows access for group or others.The private key file is readable by other usersFix - 6
The key works in PuTTY or Pageant, but git pull from Git Bash fails with the same publickey error.A PuTTY key is in use, but Git talks to a different SSH clientFix
- 1
What does the error look like?
Permission denied (publickey).remote: Permission denied (publickey)The requested repository either does not exist or you do not have access.fatal: Could not read from remote repository.
Cause 1 of 6
The public key was never added to your Bitbucket account
1Check
In Bitbucket open the Settings cog, choose Personal Bitbucket settings, then SSH keys under Security (bitbucket.org/account/settings/ssh-keys/). Print the public key on your computer and compare it with what is listed.
ls ~/.ssh/*.pub
cat ~/.ssh/id_ed25519.pub2Fix
Create a key pair if you have none, then paste the whole content of the .pub file into the Key field and choose Add key. Never paste the private key.
ssh-keygen -t ed25519 -C "you@example.com" -f ~/.ssh/id_ed25519_bitbucket
cat ~/.ssh/id_ed25519_bitbucket.pub3Verify
The test now says you are authenticated via ssh key and that shell access is disabled.
ssh -i ~/.ssh/id_ed25519_bitbucket -T git@ssh.bitbucket.orgConfirmed by support.atlassian.com
Cause 2 of 6
The SSH agent does not hold the key, or offers other keys first
1Check
List what the agent currently holds. If your key is missing from the list, ssh has no way to use it.
ssh-add -l2Fix
Load the key, and pin it in ~/.ssh/config so ssh sends that key and no other for Bitbucket.
eval $(ssh-agent)
ssh-add ~/.ssh/id_ed25519_bitbucket
# ~/.ssh/config
Host bitbucket.org ssh.bitbucket.org
AddKeysToAgent yes
IdentityFile ~/.ssh/id_ed25519_bitbucket
IdentitiesOnly yes3Verify
ssh-add -l lists the key, and the test from the first step succeeds.
ssh-add -l
ssh -T git@ssh.bitbucket.orgConfirmed by support.atlassian.com
Cause 3 of 6
You use more than one Bitbucket account and the other account's key goes first
1Check
Bitbucket tells accounts apart by the key it receives. If the debug output names the identity file of your other account, that account is the one Bitbucket sees, and it has no access to this repository.
ssh -T -vvv git@ssh.bitbucket.org 2>&1 | grep -i identity2Fix
Give each account its own Host alias with its own key and IdentitiesOnly, then point the remote at the alias.
# ~/.ssh/config
Host bb-work
HostName ssh.bitbucket.org
User git
IdentityFile ~/.ssh/id_ed25519_work
IdentitiesOnly yes
git remote set-url origin bb-work:WORKSPACE/REPO.git3Verify
The remote answers with the repository's refs instead of an access error.
git ls-remote originConfirmed by confluence.atlassian.com
Cause 4 of 6
An older RSA key whose SHA-1 signature is no longer accepted
1Check
Atlassian ties this to the RSA SHA-1 (ssh-rsa) algorithm being phased out: newer SSH clients refuse it, so a key made for it may stop working.
ssh -vvv git@ssh.bitbucket.org 2>&1 | grep 'no mutual signature'2Fix
Make a new Ed25519 key and add its public half in Bitbucket. If the failing job is a Bitbucket Pipelines build, switch the build image to a newer one, because the default image's older OpenSSH still uses SHA-1 for RSA keys.
ssh-keygen -t ed25519 -C "you@example.com"
# bitbucket-pipelines.yml
image: atlassian/default-image:43Verify
The grep from the check prints nothing, and the test succeeds with the new key.
ssh -T -vvv git@ssh.bitbucket.org 2>&1 | grep -c 'no mutual signature'Confirmed by support.atlassian.com
Cause 5 of 6
The private key file is readable by other users
1Check
Atlassian notes that the agent might not use a private key whose permissions are too open: the file should be readable and writable by you alone.
ls -l ~/.ssh/id_ed25519_bitbucket2Fix
On macOS or Linux, restrict the file to your user. On Windows, open the key file's Properties, go to the Security tab and leave only SYSTEM, Administrators and your own user with read and write access.
chmod 600 ~/.ssh/id_ed25519_bitbucket3Verify
ls -l shows -rw------- and the test from the first step passes.
ls -l ~/.ssh/id_ed25519_bitbucketConfirmed by support.atlassian.com
Cause 6 of 6
A PuTTY key is in use, but Git talks to a different SSH client
1Check
A .ppk file is not in OpenSSH format. Separately, the GIT_SSH variable can send Git to Pageant or plink instead of OpenSSH. Look at both.
ls ~/.ssh
echo "$GIT_SSH"2Fix
In PuTTYgen choose File, Load private key, pick the .ppk, then Conversions, Export OpenSSH key, and save it as id_rsa in C:\Users\YOU\.ssh. If GIT_SSH points at a PuTTY tool and you want OpenSSH, remove or correct that system variable and restart your terminals and IDE.
# after exporting, load it and test
ssh-add ~/.ssh/id_rsa
ssh -T git@ssh.bitbucket.org3Verify
ssh-add -l lists the key, and Git Bash and the test authenticate.
ssh-add -lConfirmed by support.atlassian.com
How do I stop it coming back?
- Keep one key per Bitbucket account and name the file after the account, so the debug output shows which one was tried.
- Put the host, IdentityFile and IdentitiesOnly in ~/.ssh/config instead of relying on the order of keys in the agent.
- Create new keys as Ed25519 and keep private key files readable only by you.
- After changing keys, run ssh -T once before running Git, so a key problem is not mistaken for a repository problem.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Related fixes
Security
SSH refuses your key and ends with Permission denied (publickey)
user@203.0.113.10: Permission denied (publickey,password).
The server accepted the connection but found no key it would take.
5 causes, each with a fixSecurity
Entra ID token request fails: the request body must contain the parameter 'grant_type'
AADSTS900144: The request body must contain the following parameter: 'grant_type'.
The token endpoint did not find grant_type in the form body of your POST.
3 causes, each with a fixSecurity
Angular HttpClient does not add the X-XSRF-TOKEN header to a request
403 Forbidden on POST, PUT or DELETE while GET works
Angular copies the XSRF-TOKEN cookie into an X-XSRF-TOKEN header only for mutating requests to the same origin, and only when the cookie is readable by script.
5 causes, each with a fixSecurity
An [Authorize] endpoint rejects a request with a bearer token
Authorization Header sent: no Bearer token sent.
An [Authorize] endpoint without a policy name requires an authenticated user.
4 causes, each with a fixSecurity
ASP.NET Core API rejects an Angular user's token: the signature key was not found
401 Unauthorized
The API looked for the key named by the token's kid in the key set it downloaded from your Authority, and the key was not there.
4 causes, each with a fixSecurity
ASP.NET Core rejects the token before checking it: IDX12741, three segments expected
401 Unauthorized
IDX12741 means the string the API pulled out of the Authorization header is not shaped like a JWT: a signed token has three dot-separated parts and an encrypted one has five.
3 causes, each with a fix