Permanently added (RSA) to the list of known hosts. Permission denied.

Bitbucket SSH permission denied after git push

SSH authentication to Bitbucket uses public-key cryptography — your local private key must match a public key registered in your Bitbucket account settings, and the SSH agent must have the key loaded at push time.

Problem: The following warning appears when running git push:

Warning: Permanently added 'bitbucket.org,18.205.93.0' (RSA) to the list of known hosts. git@bitbucket.org: Permission denied (publickey).

Solution: You need to properly configure your SSH keys.

Step 1. Go to the user's home directory (typically accessible after connecting via SSH) and check whether id_rsa.pub exists at /home/username/.ssh/. If it does, skip to Step 2. If not, generate a new SSH key pair:

ssh-keygen

Step 2. Copy the contents of id_rsa.pub and paste them into Bitbucket Settings → SSH Keys → Add Key:

cat /home/username/.ssh/id_rsa.pub

Step 3. Add your SSH private key to the SSH agent:

ssh-add ~/.ssh/id_rsa

Step 4. Check the SSH config file:

cat ~/.ssh/config

It should contain the following:

Host bitbucket.org
    IdentityFile ~/.ssh/id_rsa

Step 5. Test the SSH connection:

ssh -Tvv git@bitbucket.org

NOTE: If ssh-add returns "Could not open a connection to your authentication agent", run eval $(ssh-agent -s) first to start the agent in the current shell session. On macOS, also check that the key is persisted in Keychain: ssh-add --apple-use-keychain ~/.ssh/id_rsa.