ノート:
- 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
. - Git Credential Manager is a secure, cross-platform alternative to using personal access tokens (PATs) and eliminates the need to manage PAT scope and expiration. For installation instructions, see Download and install in the GitCredentialManager/git-credential-manager repository.
個人アクセストークン(PAT)は、GitHub API またはコマンドラインを使用するときに GitHub への認証でパスワードの代わりに使用できます。
PAT を使用して、SAML SSO を使用する Organization が所有するリソースにアクセスする場合は、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" in the GitHub Enterprise Cloud documentation.
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. トークンを使用してコマンドラインからリポジトリにアクセスするには、[repo
] を選択します。 For more information, see "Available scopes".
トークンの作成
-
まだ検証していない場合はメールアドレスを検証します。
-
任意のページの右上で、プロフィール画像をクリックし、続いてSettings(設定)をクリックしてください。
-
In the left sidebar, click Developer settings.
-
左のサイドバーでPersonal access tokens(個人アクセストークン)をクリックしてください。
-
[Generate new token] をクリックします。
-
トークンにわかりやすい名前を付けます。
-
To give your token an expiration, select the Expiration drop-down menu, then click a default or use the calendar picker.
-
このトークンに付与するスコープ、すなわち権限を選択します。 トークンを使用してコマンドラインからリポジトリにアクセスするには、[repo] を選択します。
-
[Generate token] をクリックします。
警告: トークンはパスワードのように扱い、秘密にしてください。 API を操作する場合は、トークンをプログラムにハードコーディングするのではなく、環境変数として使用してください。
-
To use your token to authenticate to an organization that uses SAML single sign-on, authorize the token. For more information, see "Authorizing a personal access token for use with SAML single sign-on" in the GitHub Enterprise Cloud documentation.
コマンドラインでトークンを使用する
トークンを入手したなら、HTTPS経由でGitの操作をする際にパスワードの代わりにそのトークンを入力できます。
たとえば、コマンドラインでは以下のように入力できます。
$ git clone https://github.com/username/repo.git
Username: your_username
Password: your_token
個人アクセストークンは HTTPS Git 操作だけにしか使用できません。 SSH リモート URL を使用するリポジトリの場合、リモートを SSH から HTTPS に切り替える必要があります。
ユーザ名とパスワードの入力を求められない場合、資格情報がコンピュータにキャッシュされている可能性があります。 古いパスワードをトークンに交換するようキーチェーンで資格情報を更新できます。
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. 詳細は「Git に GitHub の認証情報をキャッシュする」を参照してください。