Public Keys
- List public keys for a user
- List your public keys
- Get a single public key
- Create a public key
- Update a public key
- Delete a public key
List public keys for a user
GET /users/:username/keys
Lists the verified public SSH keys for a user. This is accessible by anyone.
Response
Status: 200 OK
Link: <https://api.github.com/resource?page=2>; rel="next",
<https://api.github.com/resource?page=5>; rel="last"
[
{
"id": 1,
"key": "ssh-rsa AAA..."
}
]
List your public keys
GET /user/keys
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.
Response
Status: 200 OK
Link: <https://api.github.com/resource?page=2>; rel="next",
<https://api.github.com/resource?page=5>; rel="last"
[
{
"key_id": "012345678912345678",
"key": "2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234"
}
]
Get a single public key
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
Response
Status: 200 OK
{
"key_id": "012345678912345678",
"key": "2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234"
}
Create a public key
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.
If your GitHub Enterprise Server appliance has LDAP Sync enabled and the option to synchronize SSH keys enabled, this API is disabled and will return a 403 response. Users managed in LDAP won't be able to add an SSH key address via the API with these options enabled.
POST /user/keys
Input
| Name | Type | Description |
|---|---|---|
title |
string |
A descriptive name for the new key. Use a name that will help you recognize this key in your GitHub account. For example, if you're using a personal Mac, you might call this key "Personal MacBook Air". |
key |
string |
The public SSH key to add to your GitHub account. See "Generating a new SSH key" for guidance on how to create a public SSH key. |
Example
{
"title": "octocat@octomac",
"key": "ssh-rsa AAA..."
}
Response
Status: 201 Created
Location:
{
"key_id": "012345678912345678",
"key": "2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234"
}
Update a public key
Public keys are immutable. If you need to update a public key, remove the key and create a new one instead.
Delete a public key
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.
If your GitHub Enterprise Server appliance has LDAP Sync enabled and the option to synchronize SSH keys enabled, this API is disabled and will return a 403 response. Users managed in LDAP won't be able to remove an SSH key address via the API with these options enabled.
DELETE /user/keys/:key_id
Response
Status: 204 No Content