---
title: SSH Keys
description: 'SSH Keys endpoints: 5 operations.'
canonical: 'https://lightning.ai/docs/platform/cluster/api-reference/ssh-keys'
---
# SSH Keys {#ssh-keys}

## Apply an SSH key to a running fleet {#apply-an-ssh-key-to-a-running-fleet}

`POST /v1/fleets/{fleetId}/sshkeys`

Applies an SSH key already registered in the organization to a fleet that is already running, so its nodes accept the key without being rebuilt. The fleet and the key must both belong to the caller's organization.

Keys are only added. A key already on a node is left alone, and keys on a node that are not in the request are never removed — this endpoint cannot revoke access. Re-submitting the same key is safe and is the way to repair a fleet where an earlier attempt reached only some nodes.

Returns 202 once the work has been accepted; the keys are written to nodes asynchronously. There is no status endpoint yet; confirm by logging in. Only nodes that are already provisioned are visited. Nodes added later get the current keys of the fleet's SSH users when they are provisioned, so they receive this key only if it is registered under one of those users.

**Parameters**

| Name | In | Type | Required | Description |
|------|----|------|----------|-------------|
| `fleetId` | path | string (uuid) | Yes | Fleet identifier |
| `Idempotency-Key` | header | string | No | Unique key that makes retrying this request safe: a retry with the same key returns the first response instead of running the request again. Optional, but strongly recommended. Use a new UUID v4 for each operation, up to 255 characters. Most responses are kept for 24 hours. See API conventions for conflicts, mismatched retries and errors. Maximum length: 255. |

**Request body** (`application/json`, required)

[AddFleetSSHKeyRequest](/docs/platform/cluster/api-reference/schemas.md#addfleetsshkeyrequest)

**Responses**

| Status | Description | Body |
|--------|-------------|------|
| `202` | Key propagation accepted. Nodes are updated asynchronously. | [AddFleetSSHKeyResponse](/docs/platform/cluster/api-reference/schemas.md#addfleetsshkeyresponse) |
| `400` | Invalid fleet identifier or request body | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `401` | Missing or invalid JWT | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `403` | Caller does not have the Administrator role | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `404` | Fleet or SSH key not found (or not owned by the caller's org) | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `409` | Fleet is not in a state that accepts key propagation | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `500` | Internal failure before the upstream call | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `502` | Upstream infrastructure returned an error | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |

## Revoke an SSH key from a running fleet {#revoke-an-ssh-key-from-a-running-fleet}

`DELETE /v1/fleets/{fleetId}/sshkeys/{sshKeyId}`

Removes every public key held by an SSH key record from a fleet's running nodes, so those nodes stop accepting them. The fleet and the key must both belong to the caller's organization.

The fleet is named explicitly, and only that fleet is touched. Other fleets holding the same key keep it, and a node that never had the user is left alone rather than having the account created for it.

The passwordless sudo rule granted to the user on this fleet is removed along with the keys. Sudo from any other source — the fleet's cloud-init, or membership of the sudo group — is not touched.

The key stays registered in the organization and can be applied again later. To delete the record itself, use `DELETE /v1/sshkeys/{sshKeyId}`.

Returns 202 once the work has been accepted; the nodes are updated asynchronously. There is no status endpoint yet; confirm by attempting to log in. Re-submitting is safe.

Nodes added to the fleet later get the current keys of the fleet's SSH users when they are provisioned, so they still receive this key while it is registered under one of those users. To stop that, delete the user with `DELETE /v1/sshkeys/{sshKeyId}`, or delete it and register it again without this key.

**Parameters**

| Name | In | Type | Required | Description |
|------|----|------|----------|-------------|
| `fleetId` | path | string (uuid) | Yes | Fleet identifier |
| `sshKeyId` | path | string (uuid) | Yes | Identifier of an SSH key record in the caller's organization. Every public key held by that record is removed from the fleet. |
| `Idempotency-Key` | header | string | No | Unique key that makes retrying this request safe: a retry with the same key returns the first response instead of running the request again. Optional, but strongly recommended. Use a new UUID v4 for each operation, up to 255 characters. Most responses are kept for 24 hours. See API conventions for conflicts, mismatched retries and errors. Maximum length: 255. |

**Responses**

| Status | Description | Body |
|--------|-------------|------|
| `202` | Key revocation accepted. Nodes are updated asynchronously. | [RemoveFleetSSHKeyResponse](/docs/platform/cluster/api-reference/schemas.md#removefleetsshkeyresponse) |
| `400` | Invalid fleet or SSH key identifier | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `401` | Missing or invalid JWT | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `403` | Caller does not have the Administrator role | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `404` | Fleet or SSH key not found (or not owned by the caller's org) | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `409` | Fleet is not in a state that accepts key changes | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `500` | Internal failure before the upstream call | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `502` | Upstream infrastructure returned an error | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |

**Example request**

```bash
curl -X DELETE "$API_URL/v1/fleets/$FLEET_ID/sshkeys/$SSH_KEY_ID" \
  -H "Authorization: Bearer $TOKEN"
```

## List your SSH keys {#list-your-ssh-keys}

`GET /v1/sshkeys`

Get all SSH keys registered for your organization. These keys are automatically installed on fleet nodes for secure access.

**When to use:**
- Show available SSH keys in your UI
- Verify which keys are registered
- Check key fingerprints before adding duplicates

**Responses**

| Status | Description | Body |
|--------|-------------|------|
| `200` | Success - returns array of SSH keys | array of [SSHKey](/docs/platform/cluster/api-reference/schemas.md#sshkey) |
| `401` | Unauthorized | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `403` | Caller does not have the permission to manage or read SSH keys | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `500` | Internal server error | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |

**Example request**

```bash
curl "$API_URL/v1/sshkeys" \
  -H "Authorization: Bearer $TOKEN"
```

**Example response** (`200`)

```json
[
  {
    "publicKeys": [
      {
        "fingerprint": "SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8"
      }
    ]
  }
]
```

## Add an SSH key {#add-an-ssh-key}

`POST /v1/sshkeys`

Register your SSH public key for secure access to fleet nodes. Once added, this key will be automatically installed on all new nodes in your fleets.

**When to use:**
- First time setup - add your SSH key before creating fleets
- Team member needs access - add their public key
- Rotate keys - add new key before removing old one

**Supported formats:** OpenSSH, RFC4716, PKCS8, PKCS1 (automatically normalized to OpenSSH)

**Idempotent:** Use `Idempotency-Key` header to safely retry if your request times out.

**Parameters**

| Name | In | Type | Required | Description |
|------|----|------|----------|-------------|
| `Idempotency-Key` | header | string | No | Unique key that makes retrying this request safe: a retry with the same key returns the first response instead of running the request again. Optional, but strongly recommended. Use a new UUID v4 for each operation, up to 255 characters. Most responses are kept for 24 hours. See API conventions for conflicts, mismatched retries and errors. Maximum length: 255. |

**Request body** (`application/json`, required)

[CreateSSHKeyRequest](/docs/platform/cluster/api-reference/schemas.md#createsshkeyrequest)

**Responses**

| Status | Description | Body |
|--------|-------------|------|
| `200` | SSH key appended to an existing user record. Returned when the request's `username` already has an SSH-key record for the caller's organization; the new public key is appended to that record and the full updated SSH key is returned. | [SSHKey](/docs/platform/cluster/api-reference/schemas.md#sshkey) |
| `201` | New SSH-key record created. Returned when the request's `username` had no SSH-key record yet for the caller's organization. | [SSHKey](/docs/platform/cluster/api-reference/schemas.md#sshkey) |
| `400` | Bad request - invalid SSH key format or validation failed | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `401` | Unauthorized | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `403` | Caller does not have the permission to manage or read SSH keys | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `409` | Conflict - duplicate key name or fingerprint | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `500` | Internal server error | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |

**Example request**

```bash
curl -X POST "$API_URL/v1/sshkeys" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"username":"john_doe","publicKey":"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl user@example.com","description":"Work laptop"}'
```

**Example response** (`200`)

```json
{
  "publicKeys": [
    {
      "fingerprint": "SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8"
    }
  ]
}
```

## Remove an SSH key {#remove-an-ssh-key}

`DELETE /v1/sshkeys/{sshKeyId}`

Remove an SSH key record, with every public key in it, from your organization.

**When to use:**
- Revoke access when a team member leaves
- Remove compromised keys
- Clean up unused keys

**Fleets:** If the user's keys were applied to running fleets with `POST /v1/fleets/{fleetId}/sshkeys`, they are taken off those fleets' nodes first. If a fleet can't be reached, the user is kept and the response is 502 with `details.fleetIds`, but the fleets that were reached are already updated; retry to finish.

**Keys installed when a fleet was created** are not removed from that fleet's running nodes. Revoke them per fleet with `DELETE /v1/fleets/{fleetId}/sshkeys/{sshKeyId}` before deleting the user. Once the user is deleted, nodes the fleet adds later no longer get the key.

**Retries:** Deleting a key that is already deleted returns 404.

**Slurm:** Slurm cluster users are separate from SSH keys. Deleting an SSH key does not change any Slurm cluster.

**Parameters**

| Name | In | Type | Required | Description |
|------|----|------|----------|-------------|
| `sshKeyId` | path | string (uuid) | Yes | SSH key identifier (from list SSH keys response) |
| `Idempotency-Key` | header | string | No | Unique key that makes retrying this request safe: a retry with the same key returns the first response instead of running the request again. Optional, but strongly recommended. Use a new UUID v4 for each operation, up to 255 characters. Most responses are kept for 24 hours. See API conventions for conflicts, mismatched retries and errors. Maximum length: 255. |

**Responses**

| Status | Description | Body |
|--------|-------------|------|
| `204` | SSH key deleted successfully | None |
| `401` | Unauthorized | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `403` | Caller does not have the permission to manage or read SSH keys | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `404` | SSH key not found | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `500` | Internal server error | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |
| `502` | The user's keys are still on one or more fleets (listed in details.fleetIds), so it was not deleted | [ErrorResponse](/docs/platform/cluster/api-reference/schemas.md#errorresponse) |

**Example request**

```bash
curl -X DELETE "$API_URL/v1/sshkeys/$SSH_KEY_ID" \
  -H "Authorization: Bearer $TOKEN"
```

---

**Navigation**

- Parent: [API reference](/docs/platform/cluster/api-reference.md)
