【问题标题】:Php execute ssh git pull script without sudo (host verification error)php执行ssh git pull脚本没有sudo(主机验证错误)
【发布时间】:2019-03-21 12:20:02
【问题描述】:

我要做什么

我在 bitbucket 上有一个 git 存储库。从本地机器推送到存储库后,我想自动将主分支拉到我的网络空间。

到目前为止我做了什么

我使用 ssh 连接到我的服务器,创建了 ssh 密钥并在 github 上注册了公钥。 我创建了一个 .sh 脚本,它使用 ssh 拉出主分支 - 到目前为止,上帝 - 当我从命令行/putty 运行脚本时,一切正常

有什么问题

我想用 bitbucket 上的 webhook 触发 .sh 脚本(我可以提供一个 url)。为此,我在我的网络空间中创建了一个 .php 文件:

<?php
$output = shell_exec('./deploy.sh 2>&1');
echo $output;

我的 .sh 脚本如下所示:

#!/bin/bash
git pull git@bitbucket.org:dualmeta/test.git master

如前所述,使用 putty 运行 .sh 脚本非常有效。但是,如果我在浏览器中输入 .php 文件的 url,它会给我一个错误:

Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

我已经做了一些研究,发现很多人都有同样的问题。但是在我的情况下,我没有 root/sudo 访问权限,因为它是一个租用的网络空间,而不是我自己的虚拟服务器。

有没有机会让它工作?

【问题讨论】:

    标签: php git ssh


    【解决方案1】:

    您必须将访问 www-data 或 apache 用户添加到您的 git 目录。

    chown -R apache:apache git_directory
    

    chown -R www-data:www-data git_directory
    

    chmod o+rw -R git_directory
    

    也使用这个:

    git config credential.helper store
    

    【讨论】:

    • 可能我做错了什么,但它对我不起作用......我使用了“chmod o+rw -R”。在我想要提取 repo 的 git 目录中。 “git config credential.helper store”和“git pull”没有做任何事情......
    • 您应该以 root 用户身份运行“git config credential.helper store”。第一次。
    • 显然我无法以 root 用户身份运行命令(如我最初的问题中所述)
    • 哦,我想你不想以 root 身份添加 php exec run 并且你有 root 访问权限。
    猜你喜欢
    • 2012-03-11
    • 1970-01-01
    • 2014-01-31
    • 1970-01-01
    • 1970-01-01
    • 2011-11-24
    • 1970-01-01
    • 2018-01-11
    • 2017-09-10
    相关资源
    最近更新 更多