我在远程服务器上的 PHP 脚本中运行 git pull 遇到了问题。我查看了很多不同的来源来使其工作,但是都没有成功。所以我迄今为止已经做了什么:
Created the pub and private key for Apache:
mkdir /var/www/.ssh sudo chown -R apache:nobody /var/www/.ssh su - apache -c "ssh-keygen -t rsa"
Then I have put my public key on Bitbucket.
Then I run the command:
sudo -u apache git pull
一切正常。
在我写了一个简单的sh
脚本之后,我从PHP
中调用它。
The .sh script:
#!/bin/sh git pull
and the PHP script:
<?php $cmd="./gitpullsc.sh 2>&1"; echo exec($cmd); ?>
Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
然后我尝试在脚本中添加`whoami`命令(以查看运行php脚本的用户是否正确),结果是apache。所以一切正常。
我使用Red Hat Linux。
希望得到任何帮助 :)
更新:
好的,也许我找到了问题所在,但还在寻找解决方案。
我再次运行`sudo -u apache git pull`命令,现在又会被要求输入私钥密码了。
但是如果我运行`ssh-add -l`命令,则返回:
2048 **thenumber** /var/www/.ssh/id_rsa (RSA)
所以我认为一切都没问题。但问题可能是我这样运行ssh代理:
ssh-agent /bin/bash
更新
是的,问题确实是密码提示。我仍然不知道如何修复它,但现在我只是将密码留空,它就可以正常工作了...