ベスパリブ

プログラミングを主とした日記・備忘録です。ベスパ持ってないです。

SSHでもBitbucketのpushやfetch時に毎回パスワード聞かれるときの対処法

ググったら似たような症状が出るわけです。

ただし上記の記事は、「HTTPSからSSHに変更したら直る」という内容です。

私の場合、SSHからHTTPSに変更したら直りました。以前まではSSH推奨であったが、今ではHTTPS推奨に変わったのでしょうか?(本当か?)推奨は時代によって変わるので、そういうことかもしれませんが確証はありません。

# リモートリポジトリのURLを表示する(git@で始まっているので、SSH接続)
$ git remote -v
origin  git@bitbucket.org:YYYY/MYPROJECT.git (fetch)
origin  git@bitbucket.org:YYYY/MYPROJECT.git (push)

# fetchすると、毎回SSHキーのパスワードを聞かれる
$ git fetch
Enter passphrase for key '/c/Users/XXXX/.ssh/bitbucket/id_ed25519':

# リモートリポジトリのURLをHTTPSに変更する
$ git remote set-url origin https://USERNAME@bitbucket.org/XXXX/MYPROJECT.git

# リモートリポジトリのURLを確認する(HTTPSになっていることを確認)
$ git remote -v
origin  https://USERNAME@bitbucket.org/YYYY/MYPROJECT.git (fetch)
origin  https://USERNAME@bitbucket.org/YYYY/MYPROJECT.git (push)

# 初回だけパスワード聞かれるが、二回目以降は聞かれなくなった
$ git fetch

ちなみにGitHubHTTPS推奨(2019年3月14日現在)というのがわかりますが、Bitbucketはそういう記事を探しても見つかりませんでした。

ただし、Change the remote URL to your repositoryの記事を読んでみると、

Update the URL for Git repositories

(中略)

If you update your URL from HTTPS to SSH, next time you push or pull from your repository, the terminal responds that it is adding the Bitbucket host to the list of known hosts. You also won't have to enter a password.

とあり、「(Gitリポジトリを)HTTPSからSSHに変更した場合は次回からパスワード聞かれない」とあります。

また、

Update the URL for Mercurial repositories

(中略)

If you update your URL from HTTPS to SSH, next time you push or pull from your repository, the terminal responds that it is adding the Bitbucket host to the list of known hosts. You also won't have to enter a password.

とあり、「(Mercurialリポジトリを)SSHからHTTPSに変更した場合は次回からパスワード聞かれない」とあります。

つまりぜんぜんわからないですが、URLを変更したらパスワードは聞かれなくなるということでしょうか。本当か?