1
0

More than 1 year has passed since last update.

Gitでpushができない時 "remote: No anonymous write access." というエラーの原因と対処法

Last updated at Posted at 2021-11-14

参考

エラー

remote: No anonymous write access.
fatal: Authentication failed for 'https://github.com/username/repo.git/'

gitでpushをすると、このようなエラーが出ました。

原因

  1. SSH接続を行なっていない
  2. SSH接続を行なった上で↓
git remote add origin

の設定がhttps://...になっていた。

対処法

1 ) SSH接続を行う

  • ターミナルを開き、下記コマンドを実行します
cd ~/.ssh 
ssh-keygen -t rsa
  • 1行めはそのままエンターを押し、任意のパスワードを入力(忘れないように)
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/(username)/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

.pubは公開鍵で、もう一つが秘密鍵です。下記コマンドのどちらかで確認が可能です。

ll
ls -l
  • 下記コマンドをそのまま入力します。実行するとクリップボードに内容が保存されます。
pbcopy < ~/.ssh/id_rsa.pub
  • Githubにアクセスし、右上のプロフィールから"Setting"に移動し、"SSH and GPG keys"に移動します。
  • "New SSH kye" を押して、"Title"に任意の文字列、"Kye"に先ほどコピーされたものをペーストします。

2 ) git remote add を変更

  • ターミナルに戻り、pushを行うフォルダに移動します。下記コマンドを実行します。
git remote -v
origin  https://github.com/username/repo.git (fetch)
origin  https://github.com/username/repo.git (push)

このように https://... となっている場合は変更が必要です。

git remote set-url origin git@github.com:username/repo.git

Githubアカウントのユーザーネームとリポジトリ名を入力したら再度"git remote -v"で確認し、買いのようになっているか確認してください。

origin  git@github.com:username/repo.git (fetch)
origin  git@github.com:username/repo.git (push)

以上で正常にpushができました。

1
0
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
1
0