Invalid SSH Key
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Problem
When adding an SSH public key to Bitbucket Cloud, the following error appears: Invalid SSH Key or Invalid SSH Key (ssh-keygen).
Cause
This error means that the data copied into the form was not able to be parsed to extract something that "looks like an SSH key". The cause of this error is that the SSH key is corrupt in some way and data pasted into the key field was modified on disk or copied incorrectly. Sometimes, this is due to line breaks being copied. Many tools will wrap the display of an SSH key. Simply highlighting and copying the key like this may copy line breaks depending on which text viewer you are using.
Diagnosis
Follow these steps to test the key on your workstation:
Diagnostic Steps:
You can test this locally by doing the following:
- Create your SSH key
Use ssh-keygen to validate the key
ssh-keygen -l -f temp.pub
- Now, copy the SSH key exactly as you had when attempting to add it to the site
- Paste the contents into a new file. Call it temp.pub
Try to use ssh-keygen again to validate the key.
ssh-keygen -l -f temp.pub
At this point, you should have a response indicating if either is invalid.
Resolution
Invalid key
If the copy is invalid, see the instructions in the above issue for copying the key properly. If both are invalid, it is possible the tool you are using to create the key is not configured properly. Try starting from the beginning of our SSH keys guide and see if starting from scratch when setting up SSH helps.
If you continue to have issues, please contact support with the output of ssh-keygen as well as your platform and what you are using to create the key.
At this moment, Bitbucket supports four encryption algorithms for user keys: Ed25519, ECDSA, RSA, and DSA.
To copy the Existing Public Key
Once you have confirmed this is the key has not been corrupted, here are the instructions to copy the ssh public key again.
Windows
- From your avatar in the bottom left, click Bitbucket settings.
Bitbucket displays the Account settings page. - Click SSH keys.
The SSH Keys page displays. It shows a list of any existing keys. Then, below that, a dialog for labeling and entering a new key. - Switch to your local desktop and start the PuTTYgen program.
- Press Load.
- Navigate to and open your default private key.
- Enter your passphrase when prompted and press OK.
The system displays your public key. - Select and copy the contents of the Public key for pasting into OpenSSH authorized_keys file field.
- Back in your browser, enter a Label for your new key, for example,
Default public key
. - Paste the copied public key into the SSH Key field:
- Press Add key.
The system adds the key and it appears in the SSH Keys listing. - Close PuTTYgen.
OSX/Linux
- From Bitbucket Cloud, choose avatar > Bitbucket settings from the application menu.
The system displays the Account settings page. - Click SSH keys.
The SSH Keys page displays. If you have any existing keys, those appear on this page. Back in your terminal window, copy the contents of your public key file.
For example, in Linux you cancat
the contents.$ cat ~/.ssh/id_rsa.pub
In Mac OS X, the following command copies the output to the clipboard:
$ pbcopy < ~/.ssh/id_rsa.pub
Back in your browser, enter a Label for your new key, for example,
Default public key
.- Paste the copied public key into the SSH Key field:
- Press Add key.
The system adds the key to your account. Bitbucket sends you an email to confirm addition of the key.