Bitbucket Data Center: "Unable to negotiate with <host> port 7999: no matching host key type found. Their offer: ssh-rsa"
Your ssh client and the Bitbucket server found no host key algorithm they both accept. The server offers only ssh-rsa (RSA with SHA-1), and OpenSSH 8.8 and later switched that off by default. It fails before any of your SSH keys is looked at, so changing to another key type does not help. The lasting fix is on the server (Bitbucket 6.6 or later offers newer algorithms); until then you can switch the algorithm back on for this one host, or use HTTPS.
What it looks like
Unable to negotiate with 192.168.0.1 port 7999: no matching host key type found. Their offer: ssh-rsa fatal: Could not read from remote repository.
Run ssh with -v and the same fact shows as debug1: kex: host key algorithm: (no match). Do not confuse it with git@<host>: Permission denied (publickey), which means the connection worked and the server did not accept your key (which key ssh offered).
This error stops Git, not the IDE's review list: Pull Request Inbox for Bitbucket, a plugin for JetBrains IDEs, reads pull requests through the Data Center REST API over HTTPS, not over SSH.
1. Confirm it
7999 is Bitbucket Data Center's default SSH port; use the host and port from git remote -v:
ssh -vT -p 7999 git@<bitbucket-host>
Find your client version with ssh -V. Atlassian's issue BSERV-13013 says the problem is OpenSSH 8.8 and later, which disable RSA signatures using SHA-1 by default, against a Bitbucket Server older than 6.6, which offered only ssh-rsa. The issue says the check fails even when the user's key is ECDSA or ED25519.
2. The fix: the server
If you run the server, or can ask whoever does, upgrade it. Per the issue, Bitbucket Server 6.6 and later (Apache Mina SSHD 2.3.0) can offer rsa-sha2-512, rsa-sha2-256 or ssh-rsa, which a current OpenSSH accepts. That is enough for this error. The issue's other half, users' own RSA keys under OpenSSH 8.8, Atlassian lists as resolved on November 18, 2021 in 6.10.15, 7.6.11, 7.15.2, 7.16.2, 7.17.2, 7.18.1, 7.19.1 and 7.20.0. Which versions Atlassian still supports: Bitbucket Data Center end of life.
3. The stopgap: allow ssh-rsa for this host
Add a block for the server only in ~/.ssh/config (C:\Users\<you>\.ssh\config on Windows), using the host name from your remote:
Host <bitbucket-host>
HostkeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa
The first line fixes this error. The second lets an RSA key of yours sign with SHA-1 as well, and you need it only if the next message is "Permission denied (publickey)" with an RSA key. In OpenSSH's configuration a leading + adds the algorithm to the default list instead of replacing it. Atlassian's issue calls this a stopgap until the legacy server can be moved. Keep it to the one host.
To see what ssh will use for the host without connecting:
ssh -G <bitbucket-host> | grep -i -E "hostkeyalgorithms|pubkeyacceptedalgorithms"
On Windows PowerShell, use ssh -G <bitbucket-host> | Select-String -Pattern "hostkeyalgorithms|pubkeyacceptedalgorithms".
4. Or use HTTPS
Atlassian's issue says HTTP is not affected. Switch the remote to the HTTPS form and sign in with a personal HTTP access token:
git remote set-url origin https://<bitbucket-host>/scm/<project-key>/<repository>.git
The token as the Git password is covered in Data Center: HTTP access token with Git.
In the IDE
Pull Request Inbox for Bitbucket, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, works with Bitbucket Data Center 8.9 or later in beta. It recognizes your repository from an SSH remote on port 7999 (Bitbucket Git remote URLs) but talks to the server through the REST API over HTTPS, with a personal HTTP access token that the IDE keeps in its password safe and sends only to that server. So this ssh error does not stop its list of pull requests waiting for your review; your own fetch and push still go through your ssh and need one of the fixes above. The review inbox, diffs and discussions are free; approving, commenting and merging are Pro, with a 30-day trial.
Get it on JetBrains Marketplace
Sources
- BSERV-13013: OpenSSH 8.8 client incompatibility (Atlassian)
- OpenSSH 8.8 client incompatibility and workaround (Atlassian Community)
- ssh_config(5): HostkeyAlgorithms, PubkeyAcceptedAlgorithms (OpenSSH manual)
Bitbucket and Atlassian are trademarks of Atlassian; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by Atlassian or JetBrains.
More: "Permission denied (publickey)" · Bitbucket Git remote URLs · Data Center: HTTP access token with Git · 日本語