【发布时间】:2018-01-11 13:44:55
【问题描述】:
我正在尝试制作一个脚本,在推送到 Bitbucket 存储库后,我可以在其中将 Git 拉到我的 ubuntu 服务器上。我已经为 Bitbucket 设置了 ssh 密钥,它可以在存储库上执行 git pull 命令,但是当我从 php exec 尝试它时它不起作用。
我已经尝试过 chmod 命令,例如 /.ssh/bitbucket_rsa,例如 775 和 777 以及 chown -R www-data:www-data/.ssh,但没有任何运气。
回复:
array (
0 => 'Host key verification failed.',
1 => 'fatal: Could not read from remote repository.',
2 => '',
3 => 'Please make sure you have the correct access rights',
4 => 'and the repository exists.',
)
代码:
public function gitPull() {
try {
exec("cd " . env("REPO_PATH") . " && git pull 2>&1", $output);
Log::info($output);
} catch (\Exception $e) {
Log::error($e);
}
http_response_code(200);
}
【问题讨论】:
-
该代码在哪个用户下运行?请查看
exec('whoami');的输出以确定。 -
'www-data' 是输出
-
你用什么用户设置了 ssh 密钥?
-
我用 root 设置了 ssh 密钥