我已经正确设置了ssh密钥并将其添加到我的github帐户中。每当我ssh进入服务器并运行git pull时,一切都会正常运行,并且会从存储库中提取更改。但是我有一个通过shell_exec()运行git pull的部署脚本,但它返回此错误;
origin git@github.com:sayopaul/autodeploy-tutorial.git (fetch)
origin git@github.com:sayopaul/autodeploy-tutorial.git (push)
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
答案 0 :(得分:1)
PHP(网络服务器)可能使用的用户身份不同。因此,它没有访问权限/ 不使用正确的SSH密钥来对GitHub进行身份验证。
我可以想到2种简单的解决方案:
sudo
:将此规则添加到sudo-conf(sudo visudo
)中,以允许用户www-data
以/usr/bin/git
的身份(仅)运行yourotheruser
:
www-data ALL=(yourotheruser) NOPASSWD: /usr/bin/git
现在您可以使用以下命令调用git
:
sudo -u yourotheruser git pull
安全建议: :如果有人设法通过www-data
执行任意代码,以限制可能造成的破坏:
创建yourotheruser
拥有的脚本(其他人不可写),例如/home/yourotheruser/deploy.sh
的内容:
cd /path/to/repo
git pull
并仅允许sudo
访问此脚本。这样,将无法在预期目录中执行除git
以外的其他pull
操作。
php-fpm
ITK MPM