15
10

More than 1 year has passed since last update.

Bitbucket Cloud recently stopped supporting account passwords for Git authentication の解決方法

Last updated at Posted at 2022-03-08

今朝 Bitbucket でブランチを push しようとしたら、昨日までは見なかったエラーに遭遇した。
スクリーンショット 2022-03-08 20.25.25.png

こやつのため一切ブランチの操作ができなくなってしまった。(めっちゃ困る。)
なんとか調べてエラーを回避できたものの、これに関して日本語の資料はあまり見当たらなかった。また質問投稿者が Windows ユーザーであることが多く、Mac を使っていた私は Bitbucket の表示項目の違いに少々悩まされた。本記事は日本語で Mac ユーザー向けにまとめてみようと思う。

エラー文全体

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 'repositoryName'
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 'repositoryName'
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 'repositoryName'
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 'repositoryName'
Completed with errors, see above

解決方法:HTTPS ではなく SSH で接続する

bitbucket で上のエラーが発生した方はリポジトリをクローンする際に HTTPS で接続していたのではないでしょうか?
私の場合は HTTPS でクローンしており、この接続を SSH に変更したところエラーが消え無事 push や pull ができるようになった。是非この機会に Bitbucket に公開鍵を登録してみてください。

エラーの原因:パスワードのサポートが終了したため

remote: Bitbucket Cloud recently stopped supporting account passwords for Git authentication.

エラー文最上行を検索すると以下の記事がヒットした。

今回のエラーに関しては事前に ATLASSIAN 社が通知しており、「HTTPS で Git に接続する際に使ったパスワードは2022/3/1にサポートが終了するよ」という内容だった。たしかに HTTPS 接続の際にユーザー名とパスワードを設定していた。3/1以降でもそのパスワードを使った接続をしていた私は見事乗り遅れ Bitbucket が使えなくなってしまったということだ。

これを回避するには SSH 接続に切り替えればよい。パソコンを変えたときに SSH の設定をめんどくさがって HTTPS 接続にしていたのが良くなかった。今回のエラーは「安全性を意識して作業せよ」という ATLASSIAN 社からの教えだろう。
Bitbucket での SSH 接続の方法をメモしておく。

HTTPS から SSH に設定を変更する

Step1:SSH キーの設定

まだ SSH キーを作成していなかったら作成する。

$ ssh-keygen // 公開鍵と秘密鍵を作成
Generating public/private rsa key pair.
Enter file in which to save the key (/ローカル/.ssh/id_rsa): // 基本的にはそのままで Enter
Enter passphrase (empty for no passphrase):
Enter same passphrase again: // 適当なパスフレーズの入力したら Enter
Your identification has been saved in /ローカル/.ssh/id_rsa.
Your public key has been saved in /ローカル/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:dkmWuvLgMgJ9qjwA2XPjF5r1ab9Uck+2gA56zKGaZd0 パコソン名.local
The key's randomart image is:
+---[RSA 3072]----+
|                 |
|           .     |
| o        +      |
|o o o o  + o     |
|.. + = oS.= + o  |
|o . = .B+B + = . |
|.. o .B.*.E   o  |
|..o o* = ..      |
|.o..oo. . ..     |
+----[SHA256]-----+
$ ls ~/.ssh/ // id_rsa(秘密鍵)とid_rsa.pub(公開鍵)が作成されたことを確認
id_rsa			id_rsa.pub

Step2:ssh-agent の追加

Key を使用する度にパスワードを入力せずに済むように設定する

$ eval `ssh-agent`
Agent pid 90773
$ ssh-add -K ~/.ssh/id_rsa
Identity added: /ローカル/.ssh/id_rsa

Step3:Configに追加

Mac OS の場合のみ、コンピューターが再起動した際にパスワードを記憶できるように config に以下の情報を追加する

Host *
UseKeychain yes

今回は vim で操作

$ vim ~/.ssh/config

Step4:公開鍵を自分の Bitbucket アカウントに追加

Bitbucket に移り、左下のアイコンから personal setting をクリックする

スクリーンショット 2022-03-08 22.38.03.png

Personal Setting のセキュリティ -> SSH 鍵から公開鍵を追加する

スクリーンショット 2022-03-08 22.40.26.png

Key には id_rsa.pub(公開鍵)の内容をすべてをペーストし、Label を書いて保存する(Label は何でも良し)

Step5:設定とユーザー名を確認

ターミナルで設定完了したどうか確認する

$ ssh -T git@bitbucket.org
... // key を使用してログインできる Bitbucket アカウントが表示されればOK
authenticated via ssh key.

You can use git to connect to Bitbucket. Shell access is disabled

Step6:HTTPS 接続から SSH 接続に切り替える

SSH の設定が完了したので、リポジトリを SSH 接続に変更する

$ git remote -v // 現在の設定を確認する
origin	https://gitName@bitbucket.org/repositoryName.git (fetch)
origin	https://gitName@bitbucket.org/repositoryName.git (push)
$ git remote set-url origin git@bitbucket.org:repositoryName.git // origin の後に SSH 用の URL を入力する

以上にて SSH の設定と BitBucket の連携が終了。
私はこれらの設定をすると、git が操作できるようになりました。
日本語の資料があれば簡単な作業も英語だと時間がかかってしまいますね。

参考
https://support.atlassian.com/ja/bitbucket-cloud/docs/set-up-an-ssh-key/
https://hodalog.com/git-remote-set-url/

あとがき

メールを遡るとちゃんと事前に ATLASSIAN 社から PASSWORD のサポート切れに関する連絡が来ていました。ちゃんとメール確認しなきゃだめですね。今回はほんと勉強になることばかりでした。

スクリーンショット 2022-03-08 23.00.31.png

15
10
1

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
15
10