ERROR: Repository not found whilst running git pull via shell_exec on php script

梦想与她 提交于 2019-12-24 09:03:29

问题


I have set up ssh keys properly and added them to my github account . Whenever I ssh into the server and run git pull , everything runs normally and it pulls changes from the repository . However I have a deploy script that runs git pull via shell_exec() but it returns this error;

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.

回答1:


PHP (the webserver) likely doesn't run as the same user you use when you SSH into the server. Thus, it doesn't have access/permission / doesn't use the correct SSH keys to authenticate vs GitHub.

I can think of 2 easy solutions:


  • Utilize sudo:

Add this rule in the sudo-conf (sudo visudo) to allow the user www-data to run (only) /usr/bin/git as yourotheruser:

www-data ALL=(yourotheruser) NOPASSWD: /usr/bin/git

Now you can invoke git using:

sudo -u yourotheruser git pull

Security advise: To limit the potential damage done if someone manages to execute arbitrary code through www-data:

Create a script owned by yourotheruser (and not writeable by others), e.g. /home/yourotheruser/deploy.sh with the contents:

cd /path/to/repo
git pull

And allow the sudo access only to this script. This way, no other git action than pull in the intended directory can be performed.


  • Change the user PHP itself is executed with:
    • Use php-fpm
    • Use the ITK MPM


来源:https://stackoverflow.com/questions/52019553/error-repository-not-found-whilst-running-git-pull-via-shell-exec-on-php-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!