ものづくりのブログ

うちのネコを題材にしたものづくりができたらいいなと思っていろいろ奮闘してます。

【github】remote: Support for password authentication was removed on August 13, 2021.

GitHubリポジトリにアクセスしようとしたら以下のようなメッセージが表示されて 「git push」が失敗してしまいました。

test@raspberrypi:~/Desktop/samples $ git push -u origin main
Username for 'https://github.com': {{user name}}
Password for 'https://{{hogehoge.com}}': 
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/{{user name}}/samples.git/'

原因

2021年8月13日以降、GitHubリポジトリにアクセスするには、ユーザ名とパスワードではなくアクセストークンが必要になったようです。

回避方法

アクセストークン作成

GitHubにログインして、右上の自分のアイコンをクリック->「Settings」をクリックします。

左メニュー下部の「Developer settings」をクリックします。

左メニューの「Personal access tokens」をクリックします。

右上の「Generate new token」をクリックしてアクセストークンを作成します。

アクセストークンの使い方

// リモートリポジトリに追加
$ git remote add origin https://{{アクセストークン}}@github.com/{{ユーザー名}}/{{リモートリポジトリ名}}.git