You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Composer相关报错求助:SSH克隆Bitbucket仓库遇公钥权限拒绝

Hey there! Let's tackle this SSH public key permission error you're hitting with Composer and Bitbucket. Even if you think your setup is solid, there are a few common gotchas that might be tripping you up.

Troubleshooting "Permission denied (publickey)" with Composer & Bitbucket

Let's walk through the most likely fixes step by step:

  • Double-check which SSH key Composer is using
    Your system might have multiple SSH keys, and Composer could be picking the wrong one. Run this command to see which key is being offered to Bitbucket:
    ssh -v git@bitbucket.org
    Look for lines like Offering public key: /path/to/your/key.pub. If this isn't the key you added to Bitbucket, create or edit your ~/.ssh/config file (or C:\Users\YourName\.ssh\config on Windows) to force SSH to use the correct key for Bitbucket:

    Host bitbucket.org
      IdentityFile /path/to/your/correct/private-key-file
    
  • Verify your public key is properly added to Bitbucket
    Head to your Bitbucket account settings > SSH keys, and confirm the public key matching your private key is listed. Make sure you copied the entire key (from ssh-rsa all the way to the end of the comment) without extra spaces, line breaks, or typos.

  • Fix SSH key file permissions
    SSH is strict about file security—if your private key has overly open permissions, it'll refuse to use it. On Linux/macOS, run these commands:
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/id_rsa (replace id_rsa with your key's filename if it's different)
    On Windows, right-click the key file > Properties > Security > Advanced, then ensure only your user account has access to it.

  • Test the SSH connection directly
    Before using Composer, confirm you can connect to Bitbucket via SSH with:
    ssh git@bitbucket.org
    If this works, you'll see a message like logged in as your-username. If this fails, the issue is with your SSH setup (not Composer). If it works but Composer still throws an error, move to the next step.

  • Clear Composer's cache
    Composer might be holding onto old connection data. Clear the cache with:
    composer clear-cache
    Then re-run your original Composer command.

  • Check your repository URL in composer.json
    Make sure the repository URL in your composer.json uses the SSH format (starts with git@bitbucket.org: instead of https://). If it's using HTTPS, switch it to SSH to match your setup.

If none of these work, try restarting your terminal or SSH agent—sometimes config changes or new keys don't take effect until you do so. You can also manually add your key to the agent with ssh-add /path/to/your/private-key-file.

内容的提问来源于stack exchange,提问作者Sergalas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 02:30:00