Creating a personal access token

You should create a personal access token to use in place of a password with the command line or with the API.

Note: If you use GitHub CLI to authenticate to GitHub on the command line, you can skip generating a personal access token and authenticate via the web browser instead. For more information about authenticating with GitHub CLI, see gh auth login.

Personal access tokens (PATs) are an alternative to using passwords for authentication to GitHub when using the GitHub API or the command line.

If you want to use a PAT to access resources owned by an organization that uses SAML SSO, you must authorize the PAT. For more information, see "About authentication with SAML single sign-on" and "Authorizing a personal access token for use with SAML single sign-on."

As a security precaution, GitHub automatically removes personal access tokens that haven't been used in a year. To provide additional security, we highly recommend adding an expiration to your personal access tokens.

A token with no assigned scopes can only access public information. To use your token to access repositories from the command line, select repo. For more information, see "Available scopes".

Creating a token

  1. Verify your email address, if it hasn't been verified yet.

  2. No canto superior direito de qualquer página, clique na sua foto de perfil e, em seguida, clique em Configurações. Ícone Settings (Configurações) na barra de usuário

  3. Na barra lateral esquerda, clique em Developer settings (Configurações do desenvolvedor). Configurações do desenvolvedor

  4. Na barra lateral esquerda, clique em tokens de acesso pessoal. Tokens de acesso pessoal

  5. Clique em Generate new token (Gerar novo token). Botão Generate new token (Gerar novo token)

  6. Give your token a descriptive name. Token description field

  7. To give your token an expiration, select the Expiration drop-down menu, then click a default or use the calendar picker. Token expiration field

  8. Select the scopes, or permissions, you'd like to grant this token. To use your token to access repositories from the command line, select repo.

    Selecting token scopes

  9. Click Generate token. Generate token button

    Newly created token

    Warning: Treat your tokens like passwords and keep them secret. When working with the API, use tokens as environment variables instead of hardcoding them into your programs.

  10. To use your token to authenticate to an organization that uses SAML SSO, authorize the token for use with a SAML single-sign-on organization.

Using a token on the command line

Se você tem um token, é possível inseri-lo em vez de sua senha ao realizar operações Git em HTTPS.

Por exemplo, você digitaria o seguinte na linha de comando:

$ git clone https://github.com/username/repo.git
Username: your_username
Password: your_token

Personal access tokens can only be used for HTTPS Git operations. If your repository uses an SSH remote URL, you will need to switch the remote from SSH to HTTPS.

If you are not prompted for your username and password, your credentials may be cached on your computer. You can update your credentials in the Keychain to replace your old password with the token.

Instead of manually entering your PAT for every HTTPS Git operation, you can cache your PAT with a Git client. Git will temporarily store your credentials in memory until an expiry interval has passed. You can also store the token in a plain text file that Git can read before every request. For more information, see "Caching your GitHub credentials in Git."

Further reading

Esse documento ajudou você?

Política de Privacidade

Ajude-nos a tornar esses documentos ótimos!

Todos os documentos do GitHub são de código aberto. Você percebeu que algo que está errado ou não está claro? Envie um pull request.

Faça uma contribuição

Ou, aprenda como contribuir.