Skip to main content
Publicamos atualizações frequentes em nossa documentação, e a tradução desta página ainda pode estar em andamento. Para obter as informações mais atualizadas, acesse a documentação em inglês.

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 application/vnd.github+json is recommended.

Parâmetros de consulta
Name, Tipo, Descrição
per_page integer

The number of results per page (max 100).

Padrão: 30

page integer

Page number of the results to fetch.

Padrão: 1

Códigos de status de resposta HTTP para "List public SSH keys for the authenticated user"

Código de statusDescriçã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"

get/user/keys
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 application/vnd.github+json is recommended.

Parâmetros do corpo
Name, Tipo, Descrição
title string

A descriptive name for the new key.

key string Obrigatório

The 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 statusDescriçã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"

post/user/keys
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 application/vnd.github+json is recommended.

Parâmetros de caminho
Name, Tipo, Descrição
key_id integer Obrigatório

The 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 statusDescriçã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"

get/user/keys/{key_id}
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 application/vnd.github+json is recommended.

Parâmetros de caminho
Name, Tipo, Descrição
key_id integer Obrigatório

The 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 statusDescriçã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"

delete/user/keys/{key_id}
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

Funciona com GitHub Apps

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 application/vnd.github+json is recommended.

Parâmetros de caminho
Name, Tipo, Descrição
username string Obrigatório

The 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: 30

page integer

Page number of the results to fetch.

Padrão: 1

Códigos de status de resposta HTTP para "List public keys for a user"

Código de statusDescrição
200

OK

Exemplos de código para "List public keys for a user"

get/users/{username}/keys
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..." } ]