Chaves SSH do Git
Use a API REST para gerenciar chaves SSH do Git de usuários autenticados.
Sobre a administração de chaves SSH do Git
Se uma URL de solicitação não incluir um parâmetro {username}
, a resposta será para o usuário conectado (e você precisará transmitir as informações de autenticação com a solicitação). Informações particulares adicionais, como se um usuário tem a autenticação de dois fatores habilitada, são incluídas quando autenticado por meio da autenticação básica ou do OAuth com o escopo user
.
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.
Parâmetros para "List public SSH keys for the authenticated user"
Cabeçalhos |
---|
Name, Tipo, Descrição |
accept string Setting to |
Parâmetros de consulta |
Name, Tipo, Descrição |
per_page integer The number of results per page (max 100). Padrão: |
page integer Page number of the results to fetch. Padrão: |
Códigos de status de resposta HTTP para "List public SSH keys for the authenticated user"
Código de status | Descrição |
---|---|
200 | OK |
304 | Not modified |
401 | Requires authentication |
403 | Forbidden |
404 | Resource not found |
Exemplos de código para "List public SSH keys for the authenticated user"
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/user/keys
Response
Status: 200
[
{
"key": "2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234",
"id": 2,
"url": "https://HOSTNAME/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://HOSTNAME/user/keys/3",
"title": "ssh-rsa AAAAB3NzaC1yc2EAAB",
"created_at": "2020-07-11T21:31:57Z",
"verified": false,
"read_only": false
}
]
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.
Parâmetros para "Create a public SSH key for the authenticated user"
Cabeçalhos |
---|
Name, Tipo, Descrição |
accept string Setting to |
Parâmetros do corpo |
Name, Tipo, Descrição |
title string A descriptive name for the new key. |
key string ObrigatórioThe public SSH key to add to your GitHub account. |
Códigos de status de resposta HTTP para "Create a public SSH key for the authenticated user"
Código de status | Descrição |
---|---|
201 | Created |
304 | Not modified |
401 | Requires authentication |
403 | Forbidden |
404 | Resource not found |
422 | Validation failed, or the endpoint has been spammed. |
Exemplos de código para "Create a public SSH key for the authenticated user"
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/user/keys \
-d '{"title":"ssh-rsa AAAAB3NzaC1yc2EAAA","key":"2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234"}'
Response
Status: 201
{
"key": "2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234",
"id": 2,
"url": "https://HOSTNAME/user/keys/2",
"title": "ssh-rsa AAAAB3NzaC1yc2EAAA",
"created_at": "2020-06-11T21:31:57Z",
"verified": false,
"read_only": false
}
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.
Parâmetros para "Get a public SSH key for the authenticated user"
Cabeçalhos |
---|
Name, Tipo, Descrição |
accept string Setting to |
Parâmetros de caminho |
Name, Tipo, Descrição |
key_id integer ObrigatórioThe unique identifier of the key. |
Códigos de status de resposta HTTP para "Get a public SSH key for the authenticated user"
Código de status | Descrição |
---|---|
200 | OK |
304 | Not modified |
401 | Requires authentication |
403 | Forbidden |
404 | Resource not found |
Exemplos de código para "Get a public SSH key for the authenticated user"
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/user/keys/KEY_ID
Response
Status: 200
{
"key": "2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234",
"id": 2,
"url": "https://HOSTNAME/user/keys/2",
"title": "ssh-rsa AAAAB3NzaC1yc2EAAA",
"created_at": "2020-06-11T21:31:57Z",
"verified": false,
"read_only": false
}
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.
Parâmetros para "Delete a public SSH key for the authenticated user"
Cabeçalhos |
---|
Name, Tipo, Descrição |
accept string Setting to |
Parâmetros de caminho |
Name, Tipo, Descrição |
key_id integer ObrigatórioThe unique identifier of the key. |
Códigos de status de resposta HTTP para "Delete a public SSH key for the authenticated user"
Código de status | Descrição |
---|---|
204 | No Content |
304 | Not modified |
401 | Requires authentication |
403 | Forbidden |
404 | Resource not found |
Exemplos de código para "Delete a public SSH key for the authenticated user"
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/user/keys/KEY_ID
Response
Status: 204
List public keys for a user
Lists the verified public SSH keys for a user. This is accessible by anyone.
Parâmetros para "List public keys for a user"
Cabeçalhos |
---|
Name, Tipo, Descrição |
accept string Setting to |
Parâmetros de caminho |
Name, Tipo, Descrição |
username string ObrigatórioThe handle for the GitHub user account. |
Parâmetros de consulta |
Name, Tipo, Descrição |
per_page integer The number of results per page (max 100). Padrão: |
page integer Page number of the results to fetch. Padrão: |
Códigos de status de resposta HTTP para "List public keys for a user"
Código de status | Descrição |
---|---|
200 | OK |
Exemplos de código para "List public keys for a user"
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/users/USERNAME/keys
Response
Status: 200
[
{
"id": 1,
"key": "ssh-rsa AAA..."
}
]