---
title: "Add a new SSH key"
method: POST
path: "/users/{selected_user}/ssh-keys"
tags: ["SSH"]
---

# Add a new SSH key

`POST /users/{selected_user}/ssh-keys`

Adds a new SSH public key to the specified user account and returns the resulting key.

Example:

```
$ curl -X POST -H "Content-Type: application/json" -d '{"key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKqP3Cr632C2dNhhgKVcon4ldUSAeKiku2yP9O9/bDtY user@myhost"}' https://api.bitbucket.org/2.0/users/{ed08f5e1-605b-4f4a-aee4-6c97628a673e}/ssh-keys
```

## Query parameters

- `expires_on` string

## Request body

- SshAccountKey — Represents an SSH public key for a user.
  - `type` string, required
  - `uuid` string — The SSH key's immutable ID.
  - `key` string — The SSH public key value in OpenSSH format.
  - `comment` string — The comment parsed from the SSH key (if present)
  - `label` string — The user-defined label for the SSH key
  - `created_on` string, date-time
  - `last_used` string, date-time
  - `links` object
    - `self` object — A link to a resource related to this object.
      - `href` string, uri
      - `name` string
  - `owner` Account — An account object.
    - `type` string, required
    - `links` AccountLinks — Links related to an Account.
      - `avatar` Link — A link to a resource related to this object.
        - `href` string, uri
        - `name` string
    - `created_on` string, date-time
    - `display_name` string
    - `uuid` string
  - `expires_on` string, date-time
  - `fingerprint` string — The SSH key fingerprint in SHA-256 format.

## Response `201`

The newly created SSH key.

- SshAccountKey — Represents an SSH public key for a user.
  - `type` string, required
  - `uuid` string — The SSH key's immutable ID.
  - `key` string — The SSH public key value in OpenSSH format.
  - `comment` string — The comment parsed from the SSH key (if present)
  - `label` string — The user-defined label for the SSH key
  - `created_on` string, date-time
  - `last_used` string, date-time
  - `links` object
    - `self` object — A link to a resource related to this object.
      - `href` string, uri
      - `name` string
  - `owner` Account — An account object.
    - `type` string, required
    - `links` AccountLinks — Links related to an Account.
      - `avatar` Link — A link to a resource related to this object.
        - `href` string, uri
        - `name` string
    - `created_on` string, date-time
    - `display_name` string
    - `uuid` string
  - `expires_on` string, date-time
  - `fingerprint` string — The SSH key fingerprint in SHA-256 format.

## Other responses

- `400` — If the submitted key or related value is invalid
- `403` — If the current user does not have permission to add a key for the specified user
- `404` — If the specified user does not exist

---

[API](https://skmtc.net/bitbucket/apis/bitbucket-api.md) · [All operations](https://skmtc.net/bitbucket/apis/bitbucket-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/bitbucket/bitbucket-api/versions/4ec8bd2515c5/schema)
