LoginSignup
34
19

More than 1 year has passed since last update.

GitHubにPushできない!?GitHubアクセストークン作成を画像で分かりやすく解説

Last updated at Posted at 2021-09-24

はじめに

GitHubでは2021年8月13日にパスワード認証が廃止されました。
https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/
よって今回はパスワードではなくアクセストークン認証によってGitHubへプッシュする方法を記載します。

HTTPS通信でGitHubにプッシュしようとしたらこんなエラーが、、。

スクリーンショット 2021-09-24 10.57.49.png

エラー内容
Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.

上記で記載した通りアクセストークンを作成し、パスワードの代わりにアクセストークン認証を使用しpushする必要があるみたい。

個人アクセストークン

参考ドキュメント
https://docs.github.com/ja/github/authenticating-to-github/creating-a-personal-access-token

アクセストークン作成手順

GitHubにログインした状態で、以下を実施します。

・設定画面( https://github.com/settings/tokens )を開く
・[Generate new token]をクリック
・noteに任意の名前を記入
・権限を設定
・[Generate token] をクリック
・トークンをコピー (ページを離れると参照不可になる)
・パスワードの代わりに使用する

注意:、権限設定で[repo] を選択します。
→これやらないとターミナルからpushする際、アクセスできないエラー403が吐かれる。

アクセストークン作成画面

設定画面トップ

スクリーンショット 2021-09-24 11.22.56.png
https://github.com/settings/tokens へ接続、右上の[Generate token] をクリック。

作成画面

スクリーンショット 2021-09-24 11.26.48.png
Noteに任意の名前(実際にコマンドに入力しないので分かりやすい名前を設定)
Expirationはトークンの有効期間なのでなるべく残したければ有効期限を長期に設定(最大1年間)
Select Scopes(権限付与)において「repo」にチェックを入れないとターミナルからpushする際アクセス権限エラー403が発生するのでチェックを忘れずに。

スクリーンショット 2021-09-24 11.33.07.png
下までスクロールし「Generate token」をクリック

アクセストークン発行画面

スクリーンショット 2021-09-24 11.35.12.png
作成後個人アクセストークンが発行されるので必ずコピーしてメモに残しておく。

実際にPushしてみる

使用例
$ git push -u origin main
Username for 'https://github.com': GitHubユーザー名
Password for 'https://'GitHubユーザー名'@github.com': ここでメモしておいた個人アクセストークンを入力
ターミナル
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 4 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (9/9), 13.43 KiB | 3.36 MiB/s, done.
Total 9 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/GitHubユーザー名/リポジトリ名.git
 * [new branch]      main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.

プッシュできました:fist:!!

34
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
34
19