php 操作git报Host key verification failed

11 篇文章 0 订阅
8 篇文章 0 订阅

1.windows

本人在用windows上,用php7.2进行git操作时,总是在报错

Cloning into 'G:\tmp\repository\git_repository\chef-server.git'...
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

本人各种检查ssh key和配置,发现没有任何错误,百思不得其解,最终使用php执行以下命令

cat ~/.ssh

发现php执行git命令时不是在系统用户目录,而是在以下目录

C:\Windows\System32\config\systemprofile\.ssh

之后将原来的id_rsa,id_rsa.pub,known_hosts移到该目录,之后便执行命令成功了

2.centos7

同样的问题在centos7上也出现了,原因是相似的,因为php所属用户不是root,通常为www,所以需为www配置ssh key,在/home/www/.ssh/目录下,添加config文件,内容如下:

#git的域名地址
Host gitlab.com
    PubkeyAcceptedKeyTypes +ssh-rsa
    HostName gitlab.com
    IdentityFile 
#你原ssh key所在位置
~/.ssh/id_rsa
    #你的git email
    User your.name@163.com
并把原ssh key地址的knwo_hosts拷贝过来就可以了


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值