Git SSH Keys
List public SSH keys for the authenticated user
Lists the public SSH keys for the authenticated user's GitHub account. Requires that you are authenticated via Basic Auth or via OAuth with at least read:public_key scope.
get /user/keysParameters
| Name | Type | In | Description |
|---|---|---|---|
accept | string | header | Setting to |
per_page | integer | query | Results per page (max 100) Default: |
page | integer | query | Page number of the results to fetch. Default: |
Code samples
Example
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user/keysawait octokit.request('GET /user/keys', {})gh api \
-H "Accept: application/vnd.github.v3+json" \
/user/keysResponse
Status: 200[
{
"key": "2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234",
"id": 2,
"url": "https://api.github.com/user/keys/2",
"title": "ssh-rsa AAAAB3NzaC1yc2EAAA",
"created_at": "2020-06-11T21:31:57Z",
"verified": false,
"read_only": false
},
{
"key": "2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJy931234",
"id": 3,
"url": "https://api.github.com/user/keys/3",
"title": "ssh-rsa AAAAB3NzaC1yc2EAAB",
"created_at": "2020-07-11T21:31:57Z",
"verified": false,
"read_only": false
}
]Status codes
| HTTP Status Code | Description |
|---|---|
200 | OK |
304 | Not modified |
401 | Requires authentication |
403 | Forbidden |
404 | Resource not found |
Create a public SSH key for the authenticated user
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.
post /user/keysParameters
| Name | Type | In | Description |
|---|---|---|---|
accept | string | header | Setting to |
title | string | body | A descriptive name for the new key. |
key | string | body | Required. The public SSH key to add to your GitHub account. |
Code samples
Example
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user/keysawait octokit.request('POST /user/keys', {})gh api \
--method POST \
-H "Accept: application/vnd.github.v3+json" \
/user/keysResponse
Status: 201{
"key": "2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234",
"id": 2,
"url": "https://api.github.com/user/keys/2",
"title": "ssh-rsa AAAAB3NzaC1yc2EAAA",
"created_at": "2020-06-11T21:31:57Z",
"verified": false,
"read_only": false
}Status codes
| HTTP Status Code | Description |
|---|---|
201 | Created |
304 | Not modified |
401 | Requires authentication |
403 | Forbidden |
404 | Resource not found |
422 | Validation failed |
Get a public SSH key for the authenticated user
View extended details for a single public SSH key. Requires that you are authenticated via Basic Auth or via OAuth with at least read:public_key scope.
get /user/keys/{key_id}Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept | string | header | Setting to |
key_id | integer | path | key_id parameter |
Code samples
Example
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user/keys/KEY_IDawait octokit.request('GET /user/keys/{key_id}', {
key_id: 'KEY_ID'
})gh api \
-H "Accept: application/vnd.github.v3+json" \
/user/keys/KEY_IDResponse
Status: 200{
"key": "2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234",
"id": 2,
"url": "https://api.github.com/user/keys/2",
"title": "ssh-rsa AAAAB3NzaC1yc2EAAA",
"created_at": "2020-06-11T21:31:57Z",
"verified": false,
"read_only": false
}Status codes
| HTTP Status Code | Description |
|---|---|
200 | OK |
304 | Not modified |
401 | Requires authentication |
403 | Forbidden |
404 | Resource not found |
Delete a public SSH key for the authenticated user
Removes a public SSH key from the authenticated user's GitHub account. Requires that you are authenticated via Basic Auth or via OAuth with at least admin:public_key scope.
delete /user/keys/{key_id}Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept | string | header | Setting to |
key_id | integer | path | key_id parameter |
Code samples
Example
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user/keys/KEY_IDawait octokit.request('DELETE /user/keys/{key_id}', {
key_id: 'KEY_ID'
})gh api \
--method DELETE \
-H "Accept: application/vnd.github.v3+json" \
/user/keys/KEY_IDResponse
Status: 204Status codes
| HTTP Status Code | Description |
|---|---|
204 | No Content |
304 | Not modified |
401 | Requires authentication |
403 | Forbidden |
404 | Resource not found |
List public keys for a user
Lists the verified public SSH keys for a user. This is accessible by anyone.
get /users/{username}/keysParameters
| Name | Type | In | Description |
|---|---|---|---|
accept | string | header | Setting to |
username | string | path | |
per_page | integer | query | Results per page (max 100) Default: |
page | integer | query | Page number of the results to fetch. Default: |
Code samples
Example
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/users/USERNAME/keysawait octokit.request('GET /users/{username}/keys', {
username: 'USERNAME'
})gh api \
-H "Accept: application/vnd.github.v3+json" \
/users/USERNAME/keysResponse
Status: 200[
{
"id": 1,
"key": "ssh-rsa AAA..."
}
]Status codes
| HTTP Status Code | Description |
|---|---|
200 | OK |