我在Github和我的服务器之间设置了一个钩子,当Github触发的脚本请求时,它可以自动提取新的提交。
所有设置完成,就像ssh-keys,git origin。我可以通过运行git pull origin master
从我在Github上托管的私人仓库中提取新提交。它适用于shell。
但是当我将该命令写入deploy.php
文件时,它可以由Github触发,但有错误信息。
Host key verification failed. fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
之后,我通过php文件运行命令whoami
,它返回用户www-data
。
实际上,我为www-data
用户生成了一个密钥,并将它们放在/var/www/.ssh
中,同时复制了id_rsa.pub
并将其粘贴到Github,但仍然存在身份验证失败。
www-data:www-data
www-data
的公钥添加到repo的部署密钥中。deploy.php
命令
shell_exec("cd /var/www/html/tinfo/; git pull origin master 2>&1;");
我的问题是
www-data
创建密钥?www-data
' .ssh
目录/var/www/.ssh
?www-data
文件并通过PHP运行命令的用户deploy.php
有关。www-data
是否未将其私钥发送到服务器? 非常感谢你。
答案 0 :(得分:1)
根据Benyi的评论,将这个问题解决了将GitHub添加到已知主机的问题。
ssh-keyscan -t rsa github.com >> /var/www/.ssh/known_hosts
首先应指定ssh密钥。之后,你应该做你想要的git任务。
1-)Ssh密钥不是用户特定的。所以你可以在任何地方创建rsa密钥对。应将公钥复制到github。私钥应放在您的主机上。
2-)在linux环境中,默认的.ssh
文件夹路径位于用户主目录下。如果您未指定用户的主文件夹,则该文件夹应位于/home/www-data/.ssh
中。如果您无法访问此文件夹,则应指定您在我的示例中编写的ssh密钥。
3-)在linux环境中,deploy.php
由执行nginx
进程的用户运行。通常由apache2
执行的nginx
和www-data user
进程。
4-)在与github服务器通信时,应指定发送此密钥文件以进行授权的ssh密钥路径。