ピックアップ
BitbucketでGit Pushしようとしたら、Permission deniedのエラーが発生した件
Bitbucketを日頃から個人的に使っていたのだが、
ある日、突然にエラーになってしまった。
その時の対応したことをメモ。
エラー内容
エラーになったのは、
Gitで反映を行おうとした時にエラー。
$ git push
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.特に今までは、
同じことをやっていてもうまくいっていた。
状況確認
一度、現在のリポジトリから、
新しく取得することを試してみる。
$ git clone https://hogehoge@bitbucket.org/hogehoge/hogehoge.git
Password for 'https://hogehoge@bitbucket.org': 【パスワード入力】これをすると、
今回はエラーになった。
remote: Bitbucket Cloud recently stopped
supporting account passwords for Git authentication.
remote: See our community post for more details:
https://atlassian.community/t5/x/x/ba-p/1948231
remote: App passwords are recommended for most use cases
and can be created in your Personal settings:
remote: https://bitbucket.org/account/settings/app-passwords/
fatal: Authentication failed for 'https://bitbucket.org/hogehoge/hogehoge.git/エラー内容を確認すると、
Bitbucket Cloud recently stopped supporting account passwords for Git authentication「Bitbucketが最近、アカウントパスワードでのGit認証をやめました」
とのことですね。
を見て確認。
対応方法
上記のページで、
This does not impact those using an SSH key to authenticate with Git.ということで、
SSHキーで接続してると問題ないらしいので、
パスワード認証でなく、SSHキー認証で対応する
まずは、公開鍵を作成する
ssh-keygen$ ssh-keygen
Enter passphrase: パスフレーズを設定
:
:
+----[SHA256]-----+作成した公開鍵を、Bitbuketに鍵情報追加。
Bitbucketの管理画面の左下から、
「Personal settings」
を選択。

開いた画面で、
「SSH鍵」
を選択して、
「鍵を追加」
をクリック。

開いたモーダルの中に、
「Key」
の部分があるので、
そこにssh-keygenで作成された公開鍵の情報を貼り付け。

この情報を、sshのconfigにも追加しておく
$ vi ~/.ssh/configVimでsshのconfigファイルを編集
Host bitbucket.org
Hostname bitbucket.org
User hogehoge
IdentityFile ~/.ssh/id_rsa
TCPKeepAlive yes
IdentitiesOnly yes対応後の動作確認
SSHでのアクセスを確認
ssh -T git@bitbucket.org$ ssh -T git@bitbucket.org
Enter passphrase for key '~/.ssh/id_rsa': 【Enter Passphrase】
authenticated via ssh key.
You can use git to connect to Bitbucket. 問題なさそうなので、
Bitbuketのリポジトリで、

クローン用のリンクを、
「SSH」
で取得して使用する。
$ git clone git@bitbucket.org:hogehoge/hogehoge.git
Enter passphrase for key 'id_rsa': 【Enter passphrase】
:
:
:
Resolving deltas: 100% (127/127), done.これでうまく取得できるようになったので完了。
おすすめ書籍
コメント一覧
コメントはまだありません。




コメントを残す