GitHubにレポジトリの作成やプッシュ時のエラー
目次
問題
GitHubに新しいレポジトリを作成したり、pushしようとすると、次のようなエラーが表示される。
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/nosuz/kicad-symbols-footprints.git/'
原因
エラーメッセージにあるようにGitHubへpushするときにパスワードではなくSSHの鍵を使用するように設定しているからです。
解決方法
gitのorigin指定を次のように修正します。これは例ですので、ユーザ名やレポジトリー名は自分のものに合わせて修正してください。
# https://github.com/nosuz/kicad-symbols-footprints.git
git@github.com:nosuz/kicad-symbols-footprints.git
解説
GitHubに新しいレポジトリーを作成すると、次のようなコマンドを実行せよと案内があります。
新しくローカルのレポジトリを作成してGitHubのレポジトリーとリンクする場合は、
echo "# kicad-symbols-footprints" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/nosuz/kicad-symbols-footprints.git
git push -u origin main
既存のレポジトリがあり、そのレポジトリを新しく作成したGitHubのレポジトリとリンクする場合は
git remote add origin https://github.com/nosuz/kicad-symbols-footprints.git
git branch -M main
git push -u origin main
となります。
しかしその通りに実行すると
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/nosuz/kicad-symbols-footprints.git/'
というエラーが表示され、GitHubのレポジトリとリンクできません。
これは、origin指定方法がSSHを使う設定と違っているからです。そお言えばSSHの鍵を登録していました。
そこで、originを次のように修正して指定します。
# 修正前 https://github.com/nosuz/kicad-symbols-footprints.git
git@github.com:nosuz/kicad-symbols-footprints.git
既にoriginを指定しようとしてエラーが出たあとであれば、.git/config
の該当箇所を同様の形式に書き換えます。そして、残りのコマンドを再度実行します。
次のステップを教えてくれるなら、ユーザーがパスワードとSSHのどちらを使っているかに合わせて案内を変えてほしかった。