Skip to main content

このバージョンの GitHub Enterprise はこの日付をもって終了となりました: 2022-10-12. 重大なセキュリティの問題に対してであっても、パッチリリースは作成されません。 パフォーマンスの向上、セキュリティの向上、新機能の向上を図るために、最新バージョンの GitHub Enterprise にアップグレードします。 アップグレードに関するヘルプについては、GitHub Enterprise サポートにお問い合わせく� さい

Creating a personal access token

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

Warning: Treat your access tokens like passwords.

To access GitHub from the command line, consider using GitHub CLI or Git Credential Manager instead of creating a personal access token.

When using a personal access token in a script, consider storing your token as a secret and running your script through GitHub Actions. For more information, see "Encrypted secrets."

If these options are not possible, consider using another service such as the 1Password CLI to store your token securely.

About personal access tokens

Personal access token are an alternative to using passwords for authentication to GitHub Enterprise Server when using the GitHub API or the command line. Personal access tokens are intended to access GitHub resources on behalf of yourself. To access resources on behalf of an organization, or for long-lived integrations, you should use a GitHub App. For more information, see "About apps."

Creating a personal access token

  1. 任意のページで、右上隅にあるプロファイルの画像をクリックし、次に[設定]をクリックします。

    ユーザバーの [Settings(設定)] アイコン

  2. In the left sidebar, click Developer settings. Developer settings

  3. In the left sidebar, click Personal access tokens. Personal access tokens

  4. [新しいトークンの生成] をクリックします。 [新しいトークンの生成] ボタン

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

  6. Select the scopes you'd like to grant this token. To use your token to access repositories from the command line, select repo. A token with no assigned scopes can only access public information. For more information, see "Available scopes".

    Selecting token scopes

  7. Click Generate token. Generate token button

    Newly created token

Using a token on the command line

トークンを入手したなら、HTTPS経由でGitの操作をする際にパスワードの代わりにそのトークンを入力できます。

たとえば、コマンドラインでは以下のように入力できます。

$ git clone https://ホスト名/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 personal access token for every HTTPS Git operation, you can cache your personal access token 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