【发布时间】:2018-08-25 17:14:37
【问题描述】:
我已经正确设置了 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.
【问题讨论】:
-
PHP(或网络服务器)是否以与您通过 SSH 连接到服务器时使用的用户相同的用户身份运行。如果没有,它可能无法访问您的用户 SSH 密钥来对 GitHub 进行身份验证。
-
嗯,非常感谢。这是有道理的。 PHP(网络服务器)作为用户 www-data 运行,而我用来通过 SSH 连接到服务器的用户是不同的。但是,如果 SSH 密钥有问题,我希望错误将是“Permission denied (Public Key)”。请问有没有办法可以更改 PHP 脚本的用户以进行测试?
-
它有点编码在 “确保您拥有正确的访问权限” 但我同意,可以更好地表述错误。我能想到一些事情,一个简单的就是利用
sudo:添加这条规则:www-data ALL=(yourotheruser) NOPASSWD: /usr/bin/git,然后像这样调用git:sudo -u yourotheruser git pull -
sudo 方法仅以另一个用户身份运行一个命令(您可以通过仅允许访问在正确目录中运行
git pull的自定义脚本来进一步限制潜在的损害)。另一种方法是更改运行 PHP 进程本身的用户,使用php-fpm或ITK MPM。 -
你好!有用 !我终于用你的建议让它工作了。你是对的,用户 www-data 没有访问 ssh 密钥的权限。我运行了“sudo visudo”并添加了规则 www-data ALL=(yourotheruser) NOPASSWD: /usr/bin/git 就像你说的那样,然后用 sudo -u yourotheruser git pull 调用了 git,现在它运行成功了。非常感谢你 ! ??????????
标签: php git shell-exec