【问题标题】:How to specify both a Bitbucket repository key and a user key such that the repository key is read-only and the user key provides push capability?如何同时指定 Bitbucket 存储库密钥和用户密钥,以使存储库密钥为只读且用户密钥提供推送功能?
【发布时间】:2022-02-08 04:32:21
【问题描述】:

Bitbucket 提供了为只读访问设置存储库的密钥。在不讨论以下方法的优点的情况下,我想使用此功能以git pull 将更改部署到网站(作为用户root),但我也想为非root 用户提供非常偶尔可以使用自己的密钥从 Web 服务器 push 到 repo。我已将root 的默认id_rsa.pub 密钥分配为Bitbucket 存储库密钥,并且pull(只读)功能在以root 登录时工作。但是,尝试从特定用户push 时出现错误。错误是:

Load key "/home/user1/.ssh/bitbucket": Permission denied
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.

我将git push 发布为user1,所以我不明白为什么在尝试加载密钥时它会给出Permission denied 错误。为什么user1 不能加载和使用自己的密钥?下面提到的两个密钥的私有部分的权限设置为 600,公共部分的权限设置为 644。

设置:

  • Ubuntu 20.04
  • 两个用户:rootuser1
  • rootid_rsa.pub 密钥添加到 Bitbucket 存储库的 访问密钥
  • user1 用于访问 Bitbucket 的密钥(名为 bitbucket.pub)已添加到用户在 BitBucket 中的 SSH Keys

/root/.ssh/ 中的 config 文件包含以下内容:

Host bitbucket.org
    HostName bitbucket.org
    IdentityFile /root/.ssh/id_rsa
    IdentitiesOnly yes

/home/user1/.ssh/ 中的 config 文件包含以下内容:

Host bitbucket.org
    HostName bitbucket.org
    User git_user1
    IdentityFile /home/user1/.ssh/bitbucket
    IdentitiesOnly yes

git remote -v 显示:

  • origin git@bitbucket.org:our_bitbucket_organization/website-name.git (fetch)
  • origin git@bitbucket.org:our_bitbucket_organization/website-name.git (push)

user1 可以 push 从他们的开发服务器到 repo - 用户是组织中的用户,repo 中的用户也是如此。我也尝试在user1 的配置文件中注释掉User 行,但得到了同样的错误。

我还研究了this question(尤其是this answer),但在其中找不到任何可以完全解决此错误的内容。我想要两个单独的 config 文件,而不是一个 config 文件。

非常感谢任何建议。

【问题讨论】:

    标签: git ssh bitbucket


    【解决方案1】:

    加载密钥“/home/user1/.ssh/bitbucket”:权限被拒绝

    该错误表示user1 无法读取该文件。修复:

    chown -R user1 /home/user1/.ssh
    chmod -R u=rwX,go= /home/user1/.ssh
    

    PS。这比仅修复一个文件更通用。以防万一。

    【讨论】:

    • 不敢相信我错过了!一个简单的权限错误。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-23
    • 2023-02-01
    相关资源
    最近更新 更多