---
title: "Keep a Legacy SSH key"
url: https://docs.corefinity.com/api/reference/access/keep-ssh-legacy-key
type: endpoint
last_updated: 2026-11-13
feature: ssh-keys
related:
  - https://docs.corefinity.com/guides/sites/access-and-security/ssh-keys.md
  - https://docs.corefinity.com/mcp/tools/corestack_ssh_legacy_key_keep.md
---
# Keep a Legacy SSH key

Keeps a Legacy key by giving it an owner, so it goes on working after the day Legacy keys end. `owner` is
the environment the key is on, that environment's website or company, or yourself. Keeping it as a company key
needs the Create Company SSH Keys permission.

```http
POST /api/ssh/keys/{key}/keep
```

- Scope: `write`
- Two-factor: required on your account (all)
- Rate limit: 60 a minute; 30 a minute for each person; 120 a minute for each company
- Long-running: answers with an operation to poll
- Try it in the console: off. It has not been cleared for the console. Copy the request and run it yourself when you are sure.

## Path parameters

- `key` (integer, required): The id of a key, as the key lists answer it in `id`. Digits only.

## Body

- `owner` (object, required): Where to keep the key. The owner of a key in a request.
  - `id` (integer, required): The id of the environment, website or company. For `user`, your own user id, which `GET /user/ssh` answers in `user_id`.
  - `type` (string, required): The level the key is held at. `user` is yourself. One of `environment`, `website`, `company`, `user`.

## Request

### curl

```bash
curl -X POST https://manage.corefinity.com/api/ssh/keys/7305/keep \
  -H "Authorization: Bearer $COREFINITY_TOKEN" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "owner": {
      "id": 1204,
      "type": "company"
    }
  }'
```

### PHP

```php
use Illuminate\Support\Facades\Http;

$response = Http::withToken(env('COREFINITY_TOKEN'))
    ->acceptJson()
    ->post('https://manage.corefinity.com/api/ssh/keys/7305/keep', [
        'owner' => [
            'id' => 1204,
            'type' => 'company',
        ],
    ]);

$data = $response->json();
```

### Node

```javascript
const res = await fetch('https://manage.corefinity.com/api/ssh/keys/7305/keep', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.COREFINITY_TOKEN}`,
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    owner: {
      id: 1204,
      type: 'company',
    },
  }),
});

// An answer with no body (204) has nothing to parse.
const text = await res.text();
const data = text && JSON.parse(text);
```

### Python

```python
import os
import requests

res = requests.post(
    "https://manage.corefinity.com/api/ssh/keys/7305/keep",
    headers={
        "Authorization": f"Bearer {os.environ['COREFINITY_TOKEN']}",
        "Accept": "application/json",
    },
    json={
        "owner": {
            "id": 1204,
            "type": "company",
        },
    },
)

data = res.json() if res.content else None
```

## Responses

### 201 The key was kept. `key` is the key at its new owner.

```json
{
  "change_id": 48214,
  "converted_from": null,
  "key": {
    "added_at": "2026-11-05T09:16:40+00:00",
    "added_by": {
      "former": false,
      "name": "Eleanor Finch",
      "support": false
    },
    "also_granted": [
      {
        "environments": 1,
        "layer": "environment",
        "owner": {
          "id": 1311,
          "name": "Production",
          "type": "environment"
        }
      }
    ],
    "applies_to": {
      "environment_ids": [],
      "mode": "all"
    },
    "bits": null,
    "delivery": {
      "applied": 0,
      "not_on_new_system": 0,
      "removed": 0,
      "state": "applying",
      "total": 1,
      "waiting": 0,
      "waiting_platform_update": 0
    },
    "editable": true,
    "fingerprint": "SHA256:Ploa6Hz7DwoHuC3xPgwJD+qGdTytelbFQ+lXDSmu+lY",
    "id": 7309,
    "last_used_at": null,
    "layer": "company",
    "legacy": null,
    "lifecycle": "active",
    "login": "web",
    "name": "deploy@build-server",
    "owner": {
      "id": 1204,
      "name": "Harbour & Finch",
      "type": "company"
    },
    "quarantine_reason": null,
    "reach": {
      "clients": 0,
      "environments": 1,
      "websites": 1
    },
    "removable": true,
    "restricted": false,
    "restrictions": [],
    "type": "ssh-ed25519",
    "weak": false
  },
  "notices": []
}
```

### 401 No token, or a token that is not valid.

```json
{
  "message": "Unauthenticated."
}
```

### 403 The token lacks the `write` scope (`scope_required`), your company requires two-factor authentication and you have not set it up, or the request is about a company key and your role lacks the permission for it (`forbidden`; `permission` names it, and `field` is null as on every SSH refusal).

```json
{
  "code": "company_unavailable",
  "message": "Your company is unavailable.",
  "reason": "company_unavailable"
}
```

### 404 The id does not exist or is something you cannot reach (`not_found`; both answer the same body), or SSH keys are not on for it (`feature_off`, which on a key change may add `field: null`).

```json
{
  "code": "feature_off",
  "message": "Not found.",
  "reason": "feature_off"
}
```

### 409 The key is already held at this owner (`ssh_key_duplicate`), or the environment shares a server with another environment that manages its keys (`ssh_managed_on_another_environment`; `managed_on` names it).

```json
{
  "code": "ssh_key_duplicate",
  "field": "public_key",
  "message": "That key is already added here.",
  "reason": "ssh_key_duplicate"
}
```

### 422 The request was refused. `reason` says why: `invalid_arguments` (`owner` is missing or wrong, or is not the key's environment, its website, its company or yourself; `field` names it), `ssh_not_legacy` (the key is not a Legacy key), `ssh_legacy_ended` (the key has already stopped working), `ssh_cap_exceeded` (the owner holds its limit of keys), `ssh_staff_key_refused` (kept at a website, a company or yourself, and the key is on Corefinity's list of staff and system keys) or `ssh_login_unavailable` and `ssh_uid_range_exhausted` (kept as your own, and a username cannot be issued for your account yet).

```json
{
  "code": "ssh_legacy_ended",
  "field": null,
  "message": "This Legacy key's cut-off has passed.",
  "reason": "ssh_legacy_ended"
}
```

### 429 Too many requests (`rate_limited`): the API's general limit, or the limit on key changes, 30 a minute for you and 120 a minute for your company across the Control Panel, this API and MCP. Wait for the number of seconds in `Retry-After`, which `retry_after_seconds` repeats. A change that meets the key limit a moment later, while it is being saved, answers `ssh_throttled` with no wait: try again in a minute.

```json
{
  "code": "ssh_throttled",
  "field": null,
  "message": "Too many SSH key changes — try again in a minute.",
  "reason": "ssh_throttled"
}
```

## If it is refused

| Status | Reason | What to do |
|---|---|---|
| 401 |  | Send a valid token as `Authorization: Bearer <token>`. |
| 403 | `company_unavailable` | Your company is unavailable. |
| 403 | `forbidden` | The person is not allowed to do this. |
| 403 | `scope_required` | Use a token with the scope named in `scope`. |
| 403 | `two_factor_required` | Turn on two-factor on your account, then send again. |
| 404 | `feature_off` | This feature is not on for your organisation yet. |
| 404 | `not_found` | Not found. |
| 409 | `ssh_key_duplicate` | The key is already added here. Use the existing one. |
| 409 | `ssh_managed_on_another_environment` | This environment's SSH is managed on another environment. Make the change on the environment the answer names. |
| 422 | `ssh_legacy_ended` | The Legacy key has already stopped working. Add the key again as a new key. |
| 422 | `ssh_not_legacy` | That is not a Legacy key. Change it as an ordinary key. |
| 429 | `ssh_throttled` | Too many SSH key changes — try again in a minute. |
| 429 | `rate_limited` | Wait for the seconds in `Retry-After`. |

## The same task elsewhere

- Guide: [SSH keys](https://docs.corefinity.com/guides/sites/access-and-security/ssh-keys.md)
- MCP tool: [`corestack_ssh_legacy_key_keep`](https://docs.corefinity.com/mcp/tools/corestack_ssh_legacy_key_keep.md)
