Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

git pull from Bitbucket Cloud over SSH is refused with a publickey error

ErrorPermission 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.

  • Applies to OpenSSH 9.x and 10.x, Git 2.4x, Bitbucket Cloud
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.org
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2The 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. 3The 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. 4The 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. 5The 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. 6The 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

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.pub

2Fix

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.pub

3Verify

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.org

Confirmed by support.atlassian.com

Did this fix it?

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 -l

2Fix

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 yes

3Verify

ssh-add -l lists the key, and the test from the first step succeeds.

ssh-add -l
ssh -T git@ssh.bitbucket.org

Confirmed by support.atlassian.com

Did this fix it?

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 identity

2Fix

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.git

3Verify

The remote answers with the repository's refs instead of an access error.

git ls-remote origin

Confirmed by confluence.atlassian.com

Did this fix it?

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:4

3Verify

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

Did this fix it?

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_bitbucket

2Fix

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_bitbucket

3Verify

ls -l shows -rw------- and the test from the first step passes.

ls -l ~/.ssh/id_ed25519_bitbucket

Confirmed by support.atlassian.com

Did this fix it?

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.org

3Verify

ssh-add -l lists the key, and Git Bash and the test authenticate.

ssh-add -l

Confirmed by support.atlassian.com

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.