---
title: "Create an SSH key"
url: https://docs.corefinity.com/api/reference/access/create-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_add.md
---
# Create an SSH key

Adds a public key at one level: a company or a website (for all or for selected environments), one
environment, or yourself. A personal key logs in with your own username; every other key logs in as `web`.
Adding a company key needs the Create Company SSH Keys permission.

```http
POST /api/ssh/keys
```

- 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.

## Body

- `applies_to` (string or object): For company and website keys only. Left out, the key applies to all environments. 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`.
- `name` (string, required): A name to recognise the key by.
- `owner` (object, required): 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`.
- `public_key` (string, required): One public key. An OpenSSH line (`ssh-ed25519 AAAA… comment`) is taken as it is; a PEM, RFC 4716 or PKCS#1 public key is converted to it. Never send a private key. At most 16,384 bytes, counted without the white space around it: a longer value is refused `ssh_key_invalid`, and one over 20,000 characters `invalid_arguments`.

## Request

### curl

```bash
curl -X POST https://manage.corefinity.com/api/ssh/keys \
  -H "Authorization: Bearer $COREFINITY_TOKEN" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "applies_to": {
      "environment_ids": [
        1311
      ],
      "mode": "selected"
    },
    "name": "Build server",
    "owner": {
      "id": 1204,
      "type": "company"
    },
    "public_key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAAAExampleKeyOnlyDoNotUseThisIsNotARealKey2"
  }'
```

### PHP

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

$response = Http::withToken(env('COREFINITY_TOKEN'))
    ->acceptJson()
    ->post('https://manage.corefinity.com/api/ssh/keys', [
        'applies_to' => [
            'environment_ids' => [
                1311,
            ],
            'mode' => 'selected',
        ],
        'name' => 'Build server',
        'owner' => [
            'id' => 1204,
            'type' => 'company',
        ],
        'public_key' => 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAAAExampleKeyOnlyDoNotUseThisIsNotARealKey2',
    ]);

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

### Node

```javascript
const res = await fetch('https://manage.corefinity.com/api/ssh/keys', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.COREFINITY_TOKEN}`,
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    applies_to: {
      environment_ids: [
        1311,
      ],
      mode: 'selected',
    },
    name: 'Build server',
    owner: {
      id: 1204,
      type: 'company',
    },
    public_key: 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAAAExampleKeyOnlyDoNotUseThisIsNotARealKey2',
  }),
});

// 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",
    headers={
        "Authorization": f"Bearer {os.environ['COREFINITY_TOKEN']}",
        "Accept": "application/json",
    },
    json={
        "applies_to": {
            "environment_ids": [
                1311,
            ],
            "mode": "selected",
        },
        "name": "Build server",
        "owner": {
            "id": 1204,
            "type": "company",
        },
        "public_key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAAAExampleKeyOnlyDoNotUseThisIsNotARealKey2",
    },
)

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

## Responses

### 201 The key was added. Follow `change_id` with `GET /ssh/changes/{change}` to see it applied.

```json
{
  "change_id": 48211,
  "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": [
        1311
      ],
      "mode": "selected"
    },
    "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:CLqzToSA4nOd3+meykf1UbpDyB5Jwm32ErgxuitkRIU",
    "id": 7307,
    "last_used_at": null,
    "layer": "company",
    "legacy": null,
    "lifecycle": "active",
    "login": "web",
    "name": "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`: a field is missing, wrong or not part of the request; `field` names it. - `ssh_key_invalid`: `public_key` is not one OpenSSH public key of a type that is accepted, or is longer than 16,384 bytes. - `ssh_private_key_refused`: a private key was sent. It was not stored. - `ssh_key_weak`: a DSA key, or an RSA key under 3072 bits; the message says which. - `ssh_key_type_unsupported`: a security key (`sk-` types), or a key of an algorithm that cannot be used for SSH. - `ssh_options_refused`: the line carries options in front of the key type. - `ssh_staff_key_refused`: the key is on Corefinity's list of staff and system keys. - `ssh_cap_exceeded`: the owner holds its limit of keys, or an environment the key reaches cannot take another (`environment` names it). - `ssh_login_unavailable`, `ssh_uid_range_exhausted`: a personal key needs a username, and one cannot be issued for your account yet.

```json
{
  "code": "invalid_arguments",
  "errors": {
    "comment": [
      "comment is not part of this request."
    ]
  },
  "field": "comment",
  "message": "comment is not part of this request.",
  "reason": "invalid_arguments"
}
```

### 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 | `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_cap_exceeded` | There are too many keys here. Remove one you no longer need. |
| 422 | `ssh_key_invalid` | That is not an SSH public key Corefinity can use. Paste one OpenSSH public key. |
| 422 | `ssh_key_weak` | The key is too weak. Use an ed25519 key, or RSA of at least 3072 bits. |
| 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_add`](https://docs.corefinity.com/mcp/tools/corestack_ssh_key_add.md)
