[英]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上,但是仍然存在身份验证失败。
www-data:www-data
www-data:www-data
www-data
's public key to the repo's deploy keys. www-data
的公钥添加到仓库的部署密钥中。 deploy.php
command
deploy.php
命令
shell_exec("cd /var/www/html/tinfo/; git pull origin master 2>&1;");
My question is 我的问题是
www-data
? www-data
创建密钥? www-data
's .ssh
directory /var/www/.ssh
? www-data
的.ssh
目录是/var/www/.ssh
吗? www-data
who execute deploy.php
file and run commands through PHP. www-data
有关,该用户执行deploy.php
文件并通过PHP运行命令。 www-data
not sent its private key to the server? 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
执行的apache2
和nginx
进程。
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.