# Create a public SSH key for the authenticated user

From **GitHub v3 REST API**.

`POST /user/keys`

Adds a public SSH key to the authenticated user's GitHub account. Requires that you are authenticated via Basic Auth, or OAuth with at least `write:public_key` [scope](https://docs.github.com/enterprise-server@3.0/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/).

## Request body

- Required: true
### `application/json`

- Type: `object`

```json
{"properties":{"key":{"description":"The public SSH key to add to your GitHub account.","pattern":"^ssh-(rsa|dss|ed25519) |^ecdsa-sha2-nistp(256|384|521) ","type":"string"},"title":{"description":"A descriptive name for the new key.","example":"Personal MacBook Air","type":"string"}},"required":["key"],"type":"object"}
```

## Responses

### `201`

Response

### `application/json`

- Type: `object`

Key

```json
{
  "created_at": "2020-06-11T21:31:57Z",
  "id": 2,
  "key": "2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234",
  "read_only": false,
  "title": "ssh-rsa AAAAB3NzaC1yc2EAAA",
  "url": "https://api.github.com/user/keys/2",
  "verified": false
}
```

```json
{"description":"Key","properties":{"created_at":{"format":"date-time","type":"string"},"id":{"type":"integer"},"key":{"type":"string"},"read_only":{"type":"boolean"},"title":{"type":"string"},"url":{"type":"string"},"verified":{"type":"boolean"}},"required":["key","id","url","title","created_at","verified","read_only"],"title":"Key","type":"object"}
```

### `304`

Not modified

### `401`

Requires authentication

### `application/json`

- Type: `object`

Basic Error

```json
{"description":"Basic Error","properties":{"documentation_url":{"type":"string"},"message":{"type":"string"},"status":{"type":"string"},"url":{"type":"string"}},"title":"Basic Error","type":"object"}
```

### `403`

Forbidden

### `application/json`

- Type: `object`

Basic Error

```json
{"description":"Basic Error","properties":{"documentation_url":{"type":"string"},"message":{"type":"string"},"status":{"type":"string"},"url":{"type":"string"}},"title":"Basic Error","type":"object"}
```

### `404`

Resource not found

### `application/json`

- Type: `object`

Basic Error

```json
{"description":"Basic Error","properties":{"documentation_url":{"type":"string"},"message":{"type":"string"},"status":{"type":"string"},"url":{"type":"string"}},"title":"Basic Error","type":"object"}
```

### `422`

Validation failed

### `application/json`

- Type: `object`

Validation Error

```json
{"description":"Validation Error","properties":{"documentation_url":{"type":"string"},"errors":{"items":{"properties":{"code":{"type":"string"},"field":{"type":"string"},"index":{"type":"integer"},"message":{"type":"string"},"resource":{"type":"string"},"value":{"oneOf":[{"nullable":true,"type":"string"},{"nullable":true,"type":"integer"},{"items":{"type":"string"},"nullable":true,"type":"array"}]}},"required":["code"],"type":"object"},"type":"array"},"message":{"type":"string"}},"required":["message","documentation_url"],"title":"Validation Error","type":"object"}
```

## Request examples

### cURL

```shell
curl --request POST \
  --url {protocol}://{hostname}/api/v3/user/keys \
  --header 'content-type: application/json' \
  --data '{
  "key": "string",
  "title": "string"
}'
```
