【发布时间】: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
- 两个用户:root 和 user1
-
root 的
id_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 文件。
非常感谢任何建议。
【问题讨论】: