我正在尝试在 CentOS VPS 上将私人存储库从 Bitbucket 克隆到 /var/www。
我在 VPS 上生成了一个 SSH 密钥对,并将 .pub 文件作为(只读)部署密钥上传到 Bitbucket。
密钥设置正确,因为当我使用以下连接时:
ssh -T git@bitbucket.org
它工作正常:
authenticated via deploy key.
You can use git or hg to connect to Bitbucket. Shell access is disabled.
This deploy key has read access to the following repositories:
<username>/<repo_name>: <Deployment Key Nickname> -- <vps_username>@<vps_hostname>
Connection to bitbucket.org closed.
到目前为止,一切都很好。但是当我尝试将 repo 克隆到 /var/www 时,我得到:
fatal: could not create work tree dir '<repo_name>'.: Permission denied
当我 sudo 时,我得到
Permission denied (publickey).
我在Bitbucket 文档中找到了有关上述错误的注释:
您在尝试连接 时使用了 sudo 在克隆存储库或使用 Bitbucket 进行任何其他 SSH 操作时,您不需要使用 sudo。
看起来我需要以 root 权限运行才能创建树,但如果我这样做了,它就没有正确使用 SSH 密钥。
因此,我对 /var/www 目录进行了 chmod,以便我的非 root 用户具有写入权限,并且一切正常。但是该目录现在是 777 (drwxrwxrwx),这可能不太好。
有没有更好的方法来处理这个?我想让 /var/www 回到 755,但我不想每次我想更新我的代码时都使用临时 chmod...
提前致谢!