Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
返回代码22,致命:git http推送失败_Git_Ssh - Fatal编程技术网

返回代码22,致命:git http推送失败

返回代码22,致命:git http推送失败,git,ssh,Git,Ssh,我在我的服务器上使用gitinit--bare创建了自己的git repo。我在那里添加了一些文件,然后通过git clone从myserver克隆了我的repohttp://www.example.com/mygit/repo而且它克隆得非常完美。现在我想通过git push origin master来推送这个目录,但它返回的是代码22。我还将我的PC的ssh公钥添加到http://www.example.com/mygit/repo/.ssh/authorized_keys但我仍然无法进入

我在我的服务器上使用
gitinit--bare
创建了自己的git repo。我在那里添加了一些文件,然后通过
git clone从myserver克隆了我的repohttp://www.example.com/mygit/repo
而且它克隆得非常完美。现在我想通过git push origin master来推送这个目录,但它返回的是代码22。我还将我的PC的ssh公钥添加到
http://www.example.com/mygit/repo/.ssh/authorized_keys
但我仍然无法进入我的repo。

/repo/.ssh/authorized_key
对服务器上的ssh守护进程没有任何意义:sshd将在进行ssh查询的用户的家中查找该文件:
/home/user/.ssh/authorized_key

另外,如果您正在使用https://... URL,您无论如何都不会使用ssh。要使ssh url正常工作,需要正确配置Apache服务器来调用。

请参阅此示例。

这是因为您使用http url而不是Github上的ssh url进行克隆。 现在,您正试图使用ssh进行推送,但这将不起作用。 在这种情况下,git clone或git pull可以工作,但git push失败

一种解决方案是使用ssh url进行克隆,其形式如下git@github.com:username/repo-name.git 当您在“您可以使用HTTPS、SSH或Subversion进行克隆”消息中单击SSH时,可以在您的Github repo上找到此url。 然后进行更改并进行git推送。确保计算机的公钥存在于Github帐户中


当前情况的另一种工作方式是在进行Git推送时提供用户名和密码。

尝试将其添加到裸存储库中的配置文件中:

[http]
       receivepack = true

为了记录在案,因为在谷歌搜索“git http push failed return code 22”时,这一点很重要:

在服务器上使用https git和htpasswd时,发送的用户名似乎包含以下域:
user@domain.tld
,但预期名称仅为
用户

我的解决方案是将其添加到
~/.netrc

machine host.domain.tld
登录\u用户名\u
密码

我的窍门是

我把它放在LocationMatch中:

 <LocationMatch /git/.*\.git>
   Dav On
   AuthType Basic
   AuthName "Git Verification"
   AuthUserFile /etc/httpd/git/test.passwd
   Require valid-user
 </LocationMatch>

达文
AuthType Basic
AuthName“Git验证”
AuthUserFile/etc/httpd/git/test.passwd
需要有效用户

你能检查一下你的http错误日志,看看那里是否有错误显示吗?我试过了,但不管用。我仍在寻找解决方案。错误可能取决于很多原因。使用服务器http日志会有很大帮助。除此之外,每次使用新克隆时,我都会遇到这个问题。需要在url设置中将“用户名@”添加到配置文件中。所以url=将成为url=