Lesstep
Bitbucket Cloud・SSH の Git・2026年10月30日に確認

Bitbucket の「git@bitbucket.org: Permission denied (publickey).」

Bitbucket Cloud は、ssh が出した鍵がどれも Bitbucket のアカウントに無く、リポジトリのアクセスキーでもないとき、この1行で答えます。ssh が鍵を1つも出さなかったときも同じ答えです。なので最初に、ssh がどの鍵を出したかを見ます。リモートを ssh.bitbucket.org に変えてから出始めたなら(Atlassian は2026年12月10日までの切り替えを求めています)、先に ~/.ssh/config を見てください。

答えの全文

2026年10月30日に git が出したもの(Git for Windows 2.53 と、それに付いている OpenSSH 10.2)。公開リポジトリに、どの Bitbucket アカウントにも無い試験用の鍵で。鍵が無いときも同じ答えでした:

git ls-remote git@ssh.bitbucket.org:<workspace>/<repo>.git
git@ssh.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.

SSH では、公開リポジトリでも Bitbucket が知っている鍵が要ります。HTTPS なら、同じ公開リポジトリを git ls-remote は認証なしで一覧できました。古い住所なら、1行目は git@bitbucket.org: で始まります。

ssh がどの鍵を出したかを見る

リモートのホスト(git remote -v で出ます)に、-v を付けて ssh します。git が使う ssh で試すこと。Windows では、打った ssh と git の ssh が別のことがあります(下):

ssh -vT git@ssh.bitbucket.org

見る行は次のとおり。bitbucket_work という名前の試験用の鍵で(指紋は省略):

debug1: Authentications that can continue: publickey
debug1: Offering public key: bitbucket_work ED25519 SHA256:…
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
git@ssh.bitbucket.org: Permission denied (publickey).

通ったときは、Atlassian の設定の手引きによると authenticated via ssh key. と You can use git to connect to Bitbucket. Shell access is disabled が出ます。

ssh.bitbucket.org に変えてから出始めた

Atlassian の設定の手引きは、鍵に bitbucket_work のような名前を付け、~/.ssh/config に次を書くよう勧めています(Set up personal SSH keys on Linux):

Host bitbucket.org
  AddKeysToAgent yes
  IdentityFile ~/.ssh/bitbucket_work

この塊が効くのは、ホスト名 bitbucket.org だけです。git remote set-url で ssh.bitbucket.org に変えるか、insteadOf を使うと、ssh は ssh.bitbucket.org につなぐので、鍵の指定が外れます。ssh -G は、つながずに ssh が使う設定を出します(OpenSSH 10.2・2026年10月30日):

ssh -G bitbucket.org \
  | grep -i identityfile
identityfile ~/.ssh/bitbucket_work

ssh -G ssh.bitbucket.org \
  | grep -i identityfile
identityfile ~/.ssh/id_rsa
identityfile ~/.ssh/id_ecdsa
identityfile ~/.ssh/id_ecdsa_sk
identityfile ~/.ssh/id_ed25519
identityfile ~/.ssh/id_ed25519_sk

しばらくは動き続けることがあります。ssh-agent が持っている鍵はどのホストにも出ますし、前に古い住所を使ったとき AddKeysToAgent yes が鍵をエージェントに入れているからです。再起動の後や、エージェントの無い端末では鍵が出なくなり、Permission denied (publickey) になります。両方のホスト名を書きます:

Host bitbucket.org ssh.bitbucket.org
  AddKeysToAgent yes
  IdentityFile ~/.ssh/bitbucket_work

1台で複数の Bitbucket アカウントを使っている場合。Atlassian の Managing multiple Bitbucket user SSH keys on one device は、アカウントごとに作ったホスト名を使います:

Host bitbucket.org-work
  HostName bitbucket.org
  User git
  IdentityFile ~/.ssh/bitbucket_work
  IdentitiesOnly yes

git@bitbucket.org-work:<workspace>/<repo>.git のようなリモートは HostName につなぎます。これは bitbucket.org のままなので、11月12日からの一時停止に当たります。insteadOf も書き換えません。git 2.53 は git@bitbucket.org:… を書き換え、git@bitbucket.org-work:… はそのままでした。各塊の HostName を ssh.bitbucket.org に変えます。すると ssh はホスト鍵を ssh.bitbucket.org の名前で探すので、known_hosts にその名前が要ります(行と指紋)。

Windows:ssh が2つ、エージェントも2つ

Windows 11 に Git for Windows を入れると、OpenSSH のクライアントが2つあります。2026年10月30日、手元の PC で:

どちらもユーザーのフォルダーの同じ .ssh を読みますが、エージェントは別々です。Git の ssh は SSH_AUTH_SOCK でエージェントを探し、これは Git Bash で eval $(ssh-agent) を打ったそのウィンドウにだけ入ります。Windows の ssh は OpenSSH Authentication Agent のサービスを使います。片方の ssh-add で入れた鍵はもう片方に無いので、PowerShell の ssh -T は通るのに git は失敗する、ということが起きます。エージェントが動いていないときの答え:

# Git Bash
ssh-add -l
Could not open a connection to your authentication agent.

# PowerShell
ssh-add -l
Error connecting to agent: No such file or directory

どちらか1つにそろえます。Atlassian の Windows の手引きは、git に Windows の ssh を使わせます:

git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe

手元の PC では、このサービスは停止中で、スタートアップの種類は「無効」でした。無効のサービスは Windows が起動しません。同じ手引きの「自動で起動する」行は sshd(SSH のサーバー)を指していて、この PC には入っていませんでした(Cannot find any service with service name 'sshd'.)。エージェントのサービス名は ssh-agent です。最初の2行は管理者の PowerShell で:

Set-Service ssh-agent `
  -StartupType Automatic
Start-Service ssh-agent
ssh-add $HOME\.ssh\bitbucket_work

または git の ssh のままにして、上のように ~/.ssh/config で両方のホスト名に鍵を指定します。IdentityFile の行は、エージェントが無くても効きます。

鍵を置く場所

ほかに:Linux と macOS では、ほかの人が読める秘密鍵を ssh は使いません。Atlassian の Permission denied (publickey) の記事は chmod 600 を挙げています。Git for Windows の ssh は、権限 644 の試験用の鍵を何も言わずに使いました。22番ポートを塞ぐネットワークでは、鍵を試す前にタイムアウトか接続拒否で失敗し、この1行にはなりません。

IntelliJ IDEA から

IntelliJ IDEA は Settings › Version Control › Git › Path to Git executable の git を動かし、その git が自分の ssh を動かします。なので上のことは端末と同じく当てはまります。同じ ~/.ssh/config を読み、Windows では core.sshCommand で変えない限り Git の ssh です。JetBrains のこの設定のページに、SSH の項目は別にありません。Git Bash の1つのウィンドウで動かしたエージェントはそのウィンドウでしか見えないので、IDE が動かす git には見えません。IdentityFile の行か、Windows のエージェントのサービスなら、どちらにも効きます。\\wsl$ から開いたプロジェクトでは、IDE は WSL の Git を使い、鍵と設定は WSL 側の ~/.ssh です。

Pull Request Inbox for Bitbucket は、JetBrains IDE 2024.1 以降で動く Lesstep のプラグインです。ワークスペースとリポジトリを git のリモート(SSH でも HTTPS でも、ssh.bitbucket.org も)から読み、Bitbucket の REST API と Atlassian のメールアドレスと API トークンで話します。SSH は使いません。なので git の SSH が失敗している間も、一時停止の間も、レビューの受信箱・差分・議論は動きます。ここまでは無料。承認・コメント・マージは Pro(月 US$1.50・30日の無料試用つき)。

JetBrains Marketplace で入れる

Bitbucket と Atlassian は Atlassian の商標、IntelliJ IDEA は JetBrains s.r.o. の商標、Windows は Microsoft の商標です。このページはそのいずれとも提携しておらず、承認も受けていません。

ほかに:Bitbucket Cloud の SSH は ssh.bitbucket.org へ · 「You may not have access to this repository」 · 「The requested URL returned error: 410」 · IntelliJ IDEA の Bitbucket プルリク用プラグインの比較 · English