---
title: "Add SSH key"
method: POST
path: "/ssh-keys"
---

# Add SSH key

`POST /ssh-keys`

Add an SSH key

To use an existing key pair, enter the public key for the `public_key` property of the request body.

To generate a new key pair, omit the `public_key` property from the request body. Save the `private_key` from the response somewhere secure. For example, with curl:

```
curl https://cloud.lambdalabs.com/api/v1/ssh-keys \
  --fail \
  -u ${LAMBDA_API_KEY}: \
  -X POST \
  -d '{"name": "new key"}' \
  | jq -r '.data.private_key' > key.pem

chmod 400 key.pem
```

Then, after you launch an instance with `new key` attached to it:
```
ssh -i key.pem <instance IP>
```

## Request body

- object — The name for the SSH key. Optionally, an existing public key can be supplied for the `public_key` property. If the `public_key` property is omitted, a new key pair is generated. The private key is returned in the response.
  - `name` string, required — Name of the SSH key
  - `public_key` string — Public key for the SSH key

## Response `200`

OK

- object — The added or generated SSH public key. If a new key pair was generated, the response body contains a `private_key` property that *must* be saved locally. Lambda Cloud does not store private keys.
  - `data` SshKey, required — Information about a stored SSH key, which can be used to access instances over SSH
    - `id` string, required — Unique identifier (ID) of an SSH key
    - `name` string, required — Name of the SSH key
    - `public_key` string, required — Public key for the SSH key
    - `private_key` string, nullable — Private key for the SSH key. Only returned when generating a new key pair.

## Other responses

- `400` — Request parameters were invalid.
- `401` — Unauthorized.
- `403` — Forbidden.

---

[API](https://skmtc.dev/unweave/apis/lambda-cloud-api.md) · [All operations](https://skmtc.dev/unweave/apis/lambda-cloud-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/unweave/lambda-cloud-api/revisions/fd68e04e7a08/schema)
