# SSH keys API

> List, save and remove the public SSH keys of your flockvm account over the API, then create VMs with a saved key's id.

- URL: https://flockvm.com/docs/api/ssh-keys
- Section: API
- Last updated: 2026-11-07

The public SSH keys saved in your account, as in **Settings → Account → SSH keys**. They belong to the user of the API key, not to the organization: every role can list, add and remove their own, and nobody else's. A saved key's `id` is what `ssh_key_id` takes when you [create a VM](https://flockvm.com/docs/api/vms#create-a-vm). Reading them needs the API key action `ssh_key.read`, saving and removing them `ssh_key.write` (see [API keys and scopes](https://flockvm.com/docs/api/api-keys#actions)).

## The SSH key object

```json
{
  "id": "key_ada_laptop",
  "name": "MacBook Pro",
  "type": "ssh-ed25519",
  "fingerprint": "SHA256:RWhaLg9VN3KnE3MJxrpaufi/snloZJuG+34a71LV83s",
  "public_key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKiNW4lwZDzfG/Ze1P65K656ZEFgAcO2+GRorZ1w/ZIe ada@acme-mbp",
  "created_at": "2026-07-29T06:16:26.971Z",
  "last_used_at": "2026-11-01T05:33:14.971Z"
}
```

`fingerprint` is the SHA256 fingerprint, as `ssh-keygen -lf` prints it. `last_used_at` is when a VM was last created with the key, `null` if never.

## List your keys

`GET /ssh-keys` · Action: `ssh_key.read`

```bash
curl https://flockvm.com/api/v1/ssh-keys \
  -H "Authorization: Bearer $FLOCKVM_API_KEY"
```

```json
{
  "ssh_keys": [
    {
      "id": "key_ada_desktop",
      "name": "Workstation",
      "type": "ssh-ed25519",
      "fingerprint": "SHA256:R2RpKxv1PPPAzjc7drFcE8fzE1IVgJwrM9n0wrFyHYM",
      "public_key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMaPnOxjby0WwoOjOhf5SlF9oLe2LMpwtAbjEMQyFGD8 ada@workstation",
      "created_at": "2026-10-02T06:16:26.971Z",
      "last_used_at": "2026-10-29T06:16:26.971Z"
    },
    {
      "id": "key_ada_laptop",
      "name": "MacBook Pro",
      "type": "ssh-ed25519",
      "fingerprint": "SHA256:RWhaLg9VN3KnE3MJxrpaufi/snloZJuG+34a71LV83s",
      "public_key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKiNW4lwZDzfG/Ze1P65K656ZEFgAcO2+GRorZ1w/ZIe ada@acme-mbp",
      "created_at": "2026-07-29T06:16:26.971Z",
      "last_used_at": "2026-11-01T05:33:14.971Z"
    }
  ]
}
```

Newest first.

## Save a key

`POST /ssh-keys` · Action: `ssh_key.write`

```bash
curl https://flockvm.com/api/v1/ssh-keys \
  -H "Authorization: Bearer $FLOCKVM_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"name\": \"laptop\", \"public_key\": \"$(cat ~/.ssh/id_ed25519.pub)\"}"
```

```text
HTTP/1.1 201 Created
```

```json
{
  "id": "key_1922th9fm6y0",
  "name": "laptop",
  "type": "ssh-ed25519",
  "fingerprint": "SHA256:fAyUo6oYkszOCeiwE+8lchsTysBMuFKDygXFda9AkW0",
  "public_key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIXJRZOf71k06biOlIfq6V/oplBHwf5Z+wB1dXm4RqPT priya@laptop",
  "created_at": "2026-11-01T06:19:35.023Z",
  "last_used_at": null
}
```

`public_key` (string, required): One OpenSSH public key on one line, the content of your `.pub` file: `ssh-ed25519`, `ssh-rsa` or `ecdsa-sha2-nistp256/384/521`. See [Accepted key formats](https://flockvm.com/docs/vms/ssh-keys#accepted-key-formats).

`name` (string, default `the key's comment, or its type`): Up to 60 characters.

You can save up to 20 keys. You can also save a key while you create a VM, with `ssh_public_key` and `"save_key": true`.

## Remove a key

`DELETE /ssh-keys/{id}` · Action: `ssh_key.write`

```bash
curl -X DELETE https://flockvm.com/api/v1/ssh-keys/key_1922th9fm6y0 \
  -H "Authorization: Bearer $FLOCKVM_API_KEY"
```

```text
HTTP/1.1 204 No Content
```

The key leaves your account. VMs that already have it keep it in their `authorized_keys`: see [Remove a key](https://flockvm.com/docs/vms/ssh-keys#remove-a-key) to take it out of a VM.

## Errors

| Status | `code`        | Example `message`                                                                                    | When                                                                                                                                                   |
| ------ | ------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 400    | `bad_request` | "Use an ssh-ed25519, ssh-rsa or ecdsa key (the line from your .pub file)." (`field`: `public_key`)   | Not a public key, or a format flockvm does not take. The other messages are in [SSH keys](https://flockvm.com/docs/vms/ssh-keys#accepted-key-formats). |
| 400    | `bad_request` | "public_key is required: an OpenSSH public key (ssh-ed25519 AAAA… comment)." (`field`: `public_key`) | No `public_key`.                                                                                                                                       |
| 400    | `bad_request` | "20 SSH keys at most: remove one first."                                                             | Your account has 20 keys.                                                                                                                              |
| 404    | `not_found`   | "This SSH key is not in your account."                                                               | No such key, or another user's.                                                                                                                        |
| 409    | `conflict`    | "This key is already in your account, as "laptop"." (`field`: `public_key`)                          | The same key is saved already.                                                                                                                         |

Saving and removing SSH keys is not in the organization's audit log, in the API as in the dashboard: keys belong to your account, not to the organization.

## Next steps

- [Create a VM](https://flockvm.com/docs/api/vms#create-a-vm): Pass a saved key's `id` as `ssh_key_id`.
- [SSH keys](https://flockvm.com/docs/vms/ssh-keys): Generate a key and add more to a running VM.
