简体   繁体   English

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

[英]Github authentication failed with user www-data

I'm setting up a hook between Github and my server, which can auto pull new commits when the script triggered by Github requests. 我正在Github和我的服务器之间建立一个钩子,当Github请求触发脚本时,它可以自动提取新提交。

It's all setting finished, like ssh-keys, git origin. 全部设置完成,如ssh-keys,git origin。 I can pull a new commit from my private repo hosted on Github by running git pull origin master . 我可以通过运行git pull origin master从Github托管的私有仓库中提取新提交。 It's works fine with the shell. 在外壳上工作正常。

But when I write that command into a deploy.php file, it can be triggered by Github, but with error message. 但是,当我将该命令写入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.

After that, I run a command whoami through the php file, it returns user www-data . 之后,我通过php文件运行命令whoami ,它返回用户www-data

Actually, I generate a key for www-data user, and put them in /var/www/.ssh , also copied id_rsa.pub and pasted it to Github, still have an authentication failure. 实际上,我为www-data用户生成了一个密钥,并将其放在/var/www/.ssh ,还复制了id_rsa.pub并将其粘贴到Github上,但是仍然存在身份验证失败。

  • nginx Nginx的
  • All files are set to belong www-data:www-data 所有文件都设置为属于www-data:www-data
  • I have add www-data 's public key to the repo's deploy keys. 我已经将www-data的公钥添加到仓库的部署密钥中。
The deploy.php command deploy.php命令
 shell_exec("cd /var/www/html/tinfo/; git pull origin master 2>&1;"); 

My question is 我的问题是

  1. How to create a key for www-data ? 如何为www-data创建密钥?
  2. Is www-data 's .ssh directory /var/www/.ssh ? www-data.ssh目录是/var/www/.ssh吗?
  3. If I'm not wrong, why does github refuse my connection? 如果我没看错,为什么github拒绝我的连接? I guess it's related about the user www-data who execute deploy.php file and run commands through PHP. 我想这与用户www-data有关,该用户执行deploy.php文件并通过PHP运行命令。
  4. When talk to Github server, does www-data not sent its private key to the server? 与Github服务器通讯时, www-data未将其私钥发送到服务器?

Thank you so much. 非常感谢。

This problem solved with adding GitHub to known hosts according to Benyi's comment. 根据Benyi的评论,通过将GitHub添加到已知主机解决了该问题。

ssh-keyscan -t rsa github.com >> /var/www/.ssh/known_hosts

You should specify ssh key firstly. 您应该首先指定ssh键。 After that, you should do git tasks what you want. 之后,您应该执行所需的git任务。

1-) Ssh keys are not user specific. 1-)Ssh键不是特定于用户的。 So you can create rsa key pair everywhere. 因此,您可以在任何地方创建rsa密钥对。 Public key should be copied to github. 公钥应复制到github。 Private key should be placed on your host. 私钥应放在主机上。

2-) In linux environment, default .ssh folder path is under the users home directory. 2-)在linux环境中,默认.ssh文件夹路径位于用户主目录下。 If you do not specify user's home folder, it should be in /home/www-data/.ssh . 如果未指定用户的主文件夹,则该文件夹应位于/home/www-data/.ssh If you can not access this folder you should specify your ssh key that have written in my example. 如果无法访问此文件夹,则应指定在我的示例中编写的ssh密钥。

3-) In linux environment, deploy.php runned by user who executing nginx process. 3-)在linux环境中,由执行nginx进程的用户运行的deploy.php Commonly apache2 and nginx processes executed by www-data user . 通常由www-data user执行的apache2nginx进程。

4-) You should specify your ssh key path for sending this key file for authorization when you talk with github server. 4-)当您与github服务器交谈时,应指定ssh密钥路径以发送此密钥文件以进行授权。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM