---
title: "Update an SSH key"
url: https://docs.corefinity.com/api/reference/access/update-ssh-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_key_update.md
---
# Update an SSH key

Renames a key, or changes the environments a company or website key applies to. A change that can take an
environment away from the key (any move to `selected` from `all`, or a shorter selection) must also send the
key's fingerprint in `confirm_fingerprint`. Changing a company key needs the Edit Company SSH Keys permission.

```http
PATCH /api/ssh/keys/{key}
```

- 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

- `applies_to` (string or object): For company and website keys only. The environments a company or website key applies to: the word `all`, `{mode: all}`, or a selection. A selection with `environment_ids` and no `mode` means `selected`.
- `confirm_fingerprint` (string): The key's fingerprint, exactly as the lists answer it. Needed when `applies_to` can take an environment away from the key, and checked whenever it is sent.
- `name` (string)

## Request

### curl

```bash
curl -X PATCH https://manage.corefinity.com/api/ssh/keys/7305 \
  -H "Authorization: Bearer $COREFINITY_TOKEN" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "applies_to": {
      "environment_ids": [
        1311
      ],
      "mode": "selected"
    },
    "confirm_fingerprint": "SHA256:o6poLLVqPDVYtxLTdagh8mUo96coeRXfX7Uxorxr158"
  }'
```

### PHP

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

$response = Http::withToken(env('COREFINITY_TOKEN'))
    ->acceptJson()
    ->patch('https://manage.corefinity.com/api/ssh/keys/7305', [
        'applies_to' => [
            'environment_ids' => [
                1311,
            ],
            'mode' => 'selected',
        ],
        'confirm_fingerprint' => 'SHA256:o6poLLVqPDVYtxLTdagh8mUo96coeRXfX7Uxorxr158',
    ]);

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

### Node

```javascript
const res = await fetch('https://manage.corefinity.com/api/ssh/keys/7305', {
  method: 'PATCH',
  headers: {
    Authorization: `Bearer ${process.env.COREFINITY_TOKEN}`,
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    applies_to: {
      environment_ids: [
        1311,
      ],
      mode: 'selected',
    },
    confirm_fingerprint: 'SHA256:o6poLLVqPDVYtxLTdagh8mUo96coeRXfX7Uxorxr158',
  }),
});

// 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.patch(
    "https://manage.corefinity.com/api/ssh/keys/7305",
    headers={
        "Authorization": f"Bearer {os.environ['COREFINITY_TOKEN']}",
        "Accept": "application/json",
    },
    json={
        "applies_to": {
            "environment_ids": [
                1311,
            ],
            "mode": "selected",
        },
        "confirm_fingerprint": "SHA256:o6poLLVqPDVYtxLTdagh8mUo96coeRXfX7Uxorxr158",
    },
)

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

## Responses

### 200 The key as it is now. `change_id` is null when nothing needs applying, as after a rename.

```json
{
  "change_id": null,
  "converted_from": null,
  "key": {
    "added_at": "2026-11-05T09:16:40+00:00",
    "added_by": {
      "former": false,
      "name": "Eleanor Finch",
      "support": false
    },
    "also_granted": [],
    "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:o6poLLVqPDVYtxLTdagh8mUo96coeRXfX7Uxorxr158",
    "id": 7305,
    "last_used_at": null,
    "layer": "company",
    "legacy": null,
    "lifecycle": "active",
    "login": "web",
    "name": "Office workstation (reception)",
    "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's environment shares a server with another environment that manages its keys (`ssh_managed_on_another_environment`; `managed_on` names it).

```json
{
  "code": "ssh_managed_on_another_environment",
  "field": null,
  "managed_on": {
    "id": 1312,
    "name": "Staging"
  },
  "message": "SSH for this server is managed on Staging.",
  "reason": "ssh_managed_on_another_environment"
}
```

### 422 The request was refused. `reason` says why: `invalid_arguments` (a field is wrong, nothing was sent to change, `applies_to` was sent for an environment or personal key, or a narrowing came without `confirm_fingerprint`; `field` names it), `confirm_mismatch` (`confirm_fingerprint` was sent and is not the key's fingerprint, whatever the change), `ssh_cap_exceeded` (an environment the key would now reach cannot take another key) or `ssh_key_invalid` (the key is set aside as not valid and can only be removed).

```json
{
  "code": "confirm_mismatch",
  "errors": {
    "confirm_fingerprint": [
      "The fingerprint you typed is not this key's."
    ]
  },
  "field": "confirm_fingerprint",
  "message": "The fingerprint you typed is not this key's.",
  "reason": "confirm_mismatch"
}
```

### 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_managed_on_another_environment` | This environment's SSH is managed on another environment. Make the change on the environment the answer names. |
| 422 | `confirm_mismatch` | Send the confirmation exactly as the field named in `field` asks for it. |
| 422 | `invalid_arguments` | The arguments do not match the tool's input schema, or the Control Panel refused a field. Fix the fields named in the answer and call again. |
| 422 | `ssh_key_invalid` | That is not an SSH public key Corefinity can use. Paste one OpenSSH public 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_key_update`](https://docs.corefinity.com/mcp/tools/corestack_ssh_key_update.md)
