Authentication failed to bitbucket
Categories:
Troubleshooting 'Authentication Failed' Errors with Bitbucket and SourceTree

Learn to diagnose and resolve common 'Authentication failed' issues when connecting to Bitbucket repositories using Atlassian SourceTree, covering SSH, HTTPS, and credential management.
Encountering an 'Authentication failed' error when trying to interact with your Bitbucket repositories through SourceTree can be a frustrating experience. This issue typically arises from misconfigured credentials, incorrect SSH keys, or problems with your network access. This article will guide you through the common causes and provide step-by-step solutions to get you back to seamless version control.
Understanding Bitbucket Authentication Methods
Bitbucket supports two primary methods for authentication: HTTPS and SSH. Each method has its own set of requirements and potential points of failure. SourceTree can be configured to use either, and understanding which one you're using is the first step in troubleshooting.
flowchart TD A[Start: Authentication Failed] --> B{Using HTTPS or SSH?} B -->|HTTPS| C[Check Bitbucket App Passwords] C --> D[Check SourceTree Saved Passwords] D --> E[Verify Bitbucket Account Credentials] B -->|SSH| F[Check SSH Key Configuration] F --> G[Verify SSH Agent is Running] G --> H[Ensure Public Key is on Bitbucket] H --> I[Test SSH Connection Manually] E --> J[Authentication Successful] I --> J
Bitbucket Authentication Troubleshooting Flow
Troubleshooting HTTPS Authentication
When using HTTPS, Bitbucket often requires an App Password instead of your main account password, especially if you have two-factor authentication (2FA) enabled. SourceTree stores these credentials, and they can become outdated or corrupted.
1. Generate a Bitbucket App Password
Log in to Bitbucket, navigate to your personal settings, then 'App passwords'. Create a new app password with appropriate permissions (e.g., 'Repositories: Read', 'Repositories: Write'). Copy this password immediately as it will only be shown once.
2. Update SourceTree Credentials
In SourceTree, go to 'Tools' > 'Options' > 'Authentication'. Find the entry for your Bitbucket account or the specific repository. Edit it to use your Bitbucket username and the newly generated app password. Alternatively, you might need to remove the old entry and re-add it.
3. Clear SourceTree's Password Cache
Sometimes, SourceTree's internal credential manager can hold onto old passwords. You might need to clear it. For Windows, this often involves the Windows Credential Manager. For macOS, it's the Keychain Access utility. Search for entries related to Bitbucket and remove them.
Troubleshooting SSH Authentication
SSH authentication relies on a pair of cryptographic keys: a private key stored locally and a public key uploaded to Bitbucket. Misconfigurations in either can lead to authentication failures.
1. Verify SSH Key Existence and Permissions
Ensure your private SSH key (e.g., id_rsa
or id_ed25519
) exists in your ~/.ssh
directory and has correct permissions (read-only for the owner, e.g., chmod 400 ~/.ssh/id_rsa
).
2. Check SSH Agent Status
Your SSH agent must be running and have your private key loaded. On Linux/macOS, use ssh-add -l
to list loaded keys. If your key isn't listed, add it with ssh-add ~/.ssh/id_rsa
. On Windows, ensure Pageant (if using PuTTY) or the built-in OpenSSH agent is running.
3. Confirm Public Key on Bitbucket
Log in to Bitbucket, go to your personal settings, then 'SSH keys'. Verify that your public key (the content of id_rsa.pub
or id_ed25519.pub
) is correctly added and enabled.
4. Test SSH Connection Manually
Open your terminal or command prompt and run ssh -T git@bitbucket.org
. You should receive a message like 'logged in as {your_username}'. If you get a permission denied error, your SSH setup is incorrect.
5. Configure SourceTree to Use Correct SSH Key
In SourceTree, go to 'Tools' > 'Options' > 'Git'. Ensure 'SSH Client' is set to 'OpenSSH' (or 'PuTTY/Plink' if you're using PuTTY keys on Windows) and that the 'SSH Key' field points to your private key file.
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
chmod 400 ~/.ssh/id_rsa
ssh-add ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub
Commands to generate an SSH key pair, set permissions, add to agent, and display public key.