用户www-data的Github身份验证失败

时间:2016-11-05 19:42:57

标签: php git nginx github ssh

我在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,但仍然存在身份验证失败。

  • nginx的
  • 所有文件都设置为www-data:www-data
  • 我已将www-data的公钥添加到repo的部署密钥中。
deploy.php命令
shell_exec("cd /var/www/html/tinfo/; git pull origin master 2>&1;");

我的问题是

  1. 如何为www-data创建密钥?
  2. www-data' .ssh目录/var/www/.ssh
  3. 如果我没错,为什么github会拒绝我的连接?我想这与执行www-data文件并通过PHP运行命令的用户deploy.php有关。
  4. 与Github服务器通话时,www-data是否未将其私钥发送到服务器?
  5. 非常感谢你。

1 个答案:

答案 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执行的nginxwww-data user进程。

4-)在与github服务器通信时,应指定发送此密钥文件以进行授权的ssh密钥路径。

相关问题