Could not add SSH key to Project and Repository

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Problem

Adding SSH key to Project and Repository Access key will fail with following appears in the atlassian-bitbucket.log

1 2 3 4 5 6 7 8 9 10 11 12 2019-02-14 08:20:30,283 ERROR [http-nio-7990-exec-5] @9W2ADRx500x81x0 xxxx xxx.xxx.xxx.xxx "POST /mvc/error500 HTTP/1.1" c.a.s.i.web.ErrorPageController There was an unhandled exception loading [/plugins/servlet/ssh/projects/TEST/keys/add] com.atlassian.activeobjects.internal.ActiveObjectsSqlException: There was a SQL exception thrown by the Active Objects library: Database: - name:PostgreSQL - version:10.4 (Ubuntu 10.4-0ubuntu0.18.04) - minor version:4 - major version:10 Driver: - name:PostgreSQL Native Driver - version:PostgreSQL 9.4.1211 org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "AO_FB71B4_SSH_PUBLIC_KEY_pkey" Detail: Key ("ENTITY_ID")=(22) already exists.

Cause

Sequence out of sync with the current data

Resolution

  1. Shutdown Bitbucket Server

  2. Run the following SQL to find the max ID number:

    1 2 3 4 SELECT MAX(public."AO_FB71B4_SSH_PUBLIC_KEY"."ENTITY_ID") FROM public."AO_FB71B4_SSH_PUBLIC_KEY";
  3. From the above result, run the following SQL to fix it:

    1 ALTER SEQUENCE public."AO_FB71B4_SSH_PUBLIC_KEY_ENTITY_ID_seq" RESTART WITH <above result + 1>;

    Replace <above result + 1> with the result from Step 3 plus 1

    Always back up your data before making any database modifications. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.

  4. Restart Bitbucket Server

Updated on April 8, 2025

Still need help?

The Atlassian Community is here for you.