[英]Php execute ssh git pull script without sudo (host verification error)
我要做什么
我在bitbucket上有一個git存儲庫。 從本地計算機推送到存儲庫后,我想自動將master分支拉到我的網站空間。
到目前為止我做了什么
我使用ssh連接到服務器,創建了ssh密鑰,並在github上注冊了公共密鑰。 我創建了一個.sh腳本,該腳本使用ssh拉了master分支-到目前為止,天啊-當我從命令行/ 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
如前所述,使用膩子運行.sh腳本可以很好地工作。 但是,如果我在瀏覽器中輸入.php文件的網址,則會出現錯誤:
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訪問權限,因為它是租用的Web空間,而不是我自己的vServer。
有機會使它起作用嗎?
您必須將訪問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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.